Number Systems
This domain tests conversion between binary, octal, decimal and hexadecimal, binary arithmetic, and signed-number representation with 1's and 2's complement.
Conversion rules
- Decimal to binary: repeated division by 2, reading remainders upward.
- Binary to octal: group bits in threes from the radix point; to hexadecimal, group in fours. Pad with zeros at the outer ends.
- Any base to decimal: multiply each digit by its positional weight (base^position).
Signed representation
In 8-bit 2's complement the leftmost bit is the sign bit (0 positive, 1 negative). Range: −128 to +127. In 1's complement the range is −127 to +127 and there are two zeros (+0 and −0). 2's complement removes the double zero, so subtraction becomes addition of the complement.
To write a negative number: write the magnitude in binary, invert all bits (1's complement), then add 1.
Worked example
Represent −25 in 8-bit 2's complement.
- 25 = 16 + 8 + 1 = 00011001.
- Invert: 11100110.
- Add 1: 11100111. Check: the sign bit is 1, so the value is negative; complementing again gives 00011001 = 25, so the stored value is −25.
Binary arithmetic
0+0=0, 1+0=1, 1+1=10 (carry 1), 1+1+1=11. Subtraction is done by adding the 2's complement of the subtrahend and discarding the final carry.
Traps
Forgetting the +1 after inversion; giving the 8-bit 2's complement range as −127 to +127; grouping bits from the wrong end when converting to hex; losing the carry in multi-bit addition.