Everything is ons and offs
01Binary representation
- Stage 1 (this one)
- Stage 2
- Stage 3
- Stage 4
- Stage 5
- Stage 6
- Stage 7
- Stage 8
- Stage 9
- Stage 10
- Stage 11
- Stage 12
- Stage 13
- Stage 14
- Stage 15
Explanation
A computer stores every number as a row of bits, each 0 or 1. In an 8-bit byte the bits are worth 128, 64, 32, 16, 8, 4, 2 and 1, from left to right. Add up the weights of the 1s and you have the value: 00100101 is 32 + 4 + 1 = 37.
A fixed number of bits means a fixed range. Eight bits hold 0 to 255. To store negative numbers, processors use two's complement: the leftmost bit is worth −128 instead of +128, so 11111111 is −1 and the range becomes −128 to 127. The same pattern of bits means different things depending on how you read it.
Flip the bits
- Binary
- 00100101
- Unsigned
- 37
- Signed (two's complement)
- 37
- Hex
- 0x25
Range with 8 bits: 0 to 255 unsigned, -128 to 127 signed. Press +1 at 255 and watch it wrap to 0.
00100101 is 37 unsigned, 37 signed
Check yourself
Marked instantly in your browser. Use the interactive above to work it out.