Key ideas
Computers store numbers in base 2, and people read them in base 8 or base 16. Converting between bases, counting the bits a value needs and reading signed values all use place values that are powers of the base.
- Each digit is weighted by a power of the base. In binary the weights are 1, 2, 4, 8, 16 and so on from the right.
- One hex digit stands for 4 bits and one octal digit for 3 bits, so grouping the bits converts directly.
- To give n items distinct codes you need ⌈log₂ n⌉ bits. n bits hold 2ⁿ different values.
- In 8-bit two’s complement a leading 1 means negative. The value is the unsigned value minus 256.
Key equations
value = Σ dᵢ × bⁱbits needed = ⌈log₂ n⌉n bits hold 2ⁿ valuestwo’s complement: value = unsigned − 2ⁿ when the top bit is 1
Worked example
Binary 101101 is 32 + 8 + 4 + 1 = 45. Hex 2F is 2 × 16 + 15 = 47. Octal 157 is 64 + 40 + 7 = 111. Giving 200 items distinct codes needs 8 bits, because 2⁷ = 128 is too small and 2⁸ = 256 is enough. The 8-bit pattern 11110110 is 246 unsigned, so as two’s complement it is 246 − 256 = −10. The pattern 10110111 has six 1 bits.
Common mistakes
- Reading binary place values from the left instead of weighting the rightmost digit as 1.
- Rounding the number of bits down. 200 items need 8 bits, not 7.
- Treating a pattern with a leading 1 as positive in two’s complement.
Practice
Test yourself with practice questions on this topic: Number systems and data