Data Representation and Number Systems
Data Representation and Number Systems tests positional number systems, base conversion, binary arithmetic, and how negative numbers and characters are encoded. Expect direct conversion questions, small 2's complement operations, and one-mark definitions of ASCII, Unicode and BCD.
Place value
In base b, a digit i places left of the radix point has weight b^i; to the right the weight is b^-i. Binary digits are bits. Groups of four bits map to one hexadecimal digit and groups of three bits map to one octal digit.
Conversion methods
- To decimal: expand the weights and add.
- From a decimal integer: divide repeatedly by the target base and read the remainders upward.
- Decimal fractions: multiply repeatedly by the target base and read the integer parts downward.
- Binary to octal or hexadecimal: regroup from the radix point outward, padding with zeros.
Negative numbers
Signed magnitude reserves the leftmost bit for the sign and has two zeros. 1's complement inverts every bit and also has two zeros. 2's complement inverts and adds 1, giving a single zero; with n bits the range is -2^(n-1) to +2^(n-1) - 1. Subtraction is performed by adding the 2's complement.
Worked example. Represent -5 in 4 bits using 2's complement. +5 is 0101; inverting gives 1010; adding 1 gives 1011. Check with weights: 1011 = -8 + 0 + 2 + 1 = -5. Because 4-bit 2's complement spans -8 to +7, the value fits.
Traps. Regrouping must start at the radix point, not at the left end. In 1's complement arithmetic the end-around carry must be added back. BCD encodes each decimal digit separately, so 25 is 0010 0101, not 11001.