Number Systems and Data Representation: Bases, Two's Complement, Codes and Gates
Number systems and data representation covers how everything inside the computer becomes binary: conversions between binary, octal, decimal and hexadecimal, negative number representation, character codes, and the logic gates from which circuits are built. Questions are short and precise - a conversion, a truth table, a two's-complement calculation - so one slip costs the whole mark.
Place value and conversion
Binary columns from the right are 1, 2, 4, 8, 16, 32, 64, 128. To convert 156: take 128 (remainder 28), take 16 (12), take 8 (4), take 4 (0), so 156 = 10011100 in binary. Group binary digits in fours from the right for hexadecimal: 1001 1100 gives 9C. Group in threes from the right for octal: 10 011 100 gives 234. Going the other way, expand each hex digit into four bits, so A3 = 1010 0011. Binary addition follows 0+0=0, 1+0=1, 1+1=10 (write 0, carry 1), 1+1+1=11.
Negative numbers and coded decimals
In n-bit two's complement the leftmost bit is the sign (0 positive, 1 negative). To write minus x, invert every bit of x and add 1. The range for n bits is minus 2^(n-1) to plus 2^(n-1) minus 1, so 8 bits give -128 to +127. BCD stores one decimal digit per 4-bit group, which suits displays and calculators but wastes space and needs correction after addition.
Character coding
ASCII uses 7 bits for 128 codes (upper and lower case, digits, punctuation, control codes); extended ASCII uses 8 bits for 256. Unicode uses 16 or more bits (UTF-8, UTF-16) to represent the world's scripts, symbols and emoji, and UTF-8 is backward compatible with ASCII.
Logic gates and Boolean expressions
Learn truth tables for NOT, AND, OR, NAND, NOR and XOR. NAND and NOR are universal - either alone can build any circuit. A half adder has SUM = A XOR B and CARRY = A AND B; a full adder combines two half adders with an OR gate for the carry.
Worked example
Represent -5 in 8-bit two's complement. +5 = 00000101. Invert: 11111010. Add 1: 11111011. Check: the sign bit is 1 (negative) and the value is -128 + 64 + 32 + 16 + 8 + 2 + 1 = -5.
Traps
Do not read BCD as pure binary; group bits from the right, never the left; a 4-bit two's complement range is -8 to +7, not -7 to +7; and XOR gives 1 only when the inputs differ.