Number Systems and Data Representation
Number Systems and Data Representation tests conversion between decimal, binary, octal and hexadecimal, binary arithmetic, and how characters are encoded. Expect short conversion and complement questions, not long programming.
Core rules
- A positional number system uses base b and place values b^0, b^1, b^2... Decimal is base 10; binary base 2; octal base 8; hexadecimal base 16 (A=10 ... F=15).
- To convert decimal to another base, divide repeatedly by the target base and read remainders bottom-to-top. To convert back, multiply each digit by its place value and add.
- Group binary bits from the right: 3 bits = 1 octal digit; 4 bits = 1 hexadecimal digit. Pad with leading zeros on the left if needed.
- Binary addition rules: 0+0=0, 0+1=1, 1+1=10 (write 0 carry 1), 1+1+1=11.
- 1's complement flips bits; 2's complement = 1's complement + 1 and represents negative numbers. ASCII is a 7-bit character code; Unicode covers many scripts and is not limited to 128 characters.
Worked example
Convert decimal 45 to binary and hexadecimal. For binary, subtract the largest powers: 45 = 32 + 8 + 4 + 1, so the bits for 32,16,8,4,2,1 are 1 0 1 1 0 1 → 101101. For hexadecimal, divide by 16: 45 ÷ 16 = 2 remainder 13; 13 is D, so read quotient and remainder as 2D. Check: 2×16 + 13 = 45.
Traps
- Reading remainders top-to-bottom instead of bottom-to-top.
- Forgetting that hexadecimal A–F are single digits, not two characters.
- Grouping binary from the left; always group from the right (least significant bit).
- Confusing 1's and 2's complement; 2's complement adds 1 after flipping.
- Writing Unicode as a 7-bit code; ASCII is the 7-bit one.