Number Systems and Data Representation
Number systems
Decimal is base 10, binary base 2, octal base 8, hexadecimal base 16. Each positional digit has weight base^position. Convert a decimal integer to base b by repeated division, reading remainders bottom-up; convert to decimal by expanding weights. Group binary bits: 3 bits = one octal digit, 4 bits = one hex digit.
Signed representation
For n bits, the unsigned range is 0 to 2^n − 1. Sign-magnitude and 1's complement have two zeros. 2's complement is standard: invert bits and add 1; range −2^(n−1) to 2^(n−1) − 1. For 8 bits: −128 to 127.
Worked example
Convert decimal 45 to binary: 45 ÷ 2 remainders 1,0,1,1,0,1 reading upward = 101101. Group from the right: 0010 1101 = 2D in hex. Check: 32 + 8 + 4 + 1 = 45. For −5 in 8 bits: +5 = 00000101; invert = 11111010; add 1 = 11111011.
Character and data codes
ASCII uses 7 bits (0–127); extended ASCII uses 8. Unicode assigns code points for global scripts. BCD stores one decimal digit per 4-bit nibble. A parity bit detects single-bit errors, not corrects them.
Traps
Do not read division remainders top-down. Do not treat the leftmost bit as a plain magnitude in 2's complement. Hex A–F are single digits, so 2D is two digits, not "2 times D". Overflow occurs when a result leaves the representable range.