Skip to content
Tactiverge

Everything is ons and offs

01Binary representation

  1. Stage 1 (this one)
  2. Stage 2
  3. Stage 3
  4. Stage 4
  5. Stage 5
  6. Stage 6
  7. Stage 7
  8. Stage 8
  9. Stage 9
  10. Stage 10
  11. Stage 11
  12. Stage 12
  13. Stage 13
  14. Stage 14
  15. 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.

  1. 1. Write 37 as an 8-bit binary number.
  2. 2. Read 11111111 as a two's-complement signed byte. What number is it?