Start here · Bits and numbers

Eight bits.
One number.

A bit can be 0 or 1. Put eight together and you have a byte. Let’s see how those bits can represent a number.

One byte · eight bitsUnsigned · 0 to 255

Enable JavaScript to change this byte. This example shows 42.

Change the byte

Hex digit 2

Hex digit A

Add the values of the bits that are on

32 + 8 + 2 = 42

Every position has a value.

Start at the right: 1, 2, 4, 8. Each position is worth twice the one before it. A 1 includes that value; a 0 leaves it out. Add the included values to find the number.

The starting byte has 32, 8, and 2 switched on. That makes 42.

Three ways to write the same number.

Binary uses two digits, 0 and 1. Each digit corresponds to one bit, so eight digits show the whole byte.

Decimal uses the ten digits we count with, 0 to 9. Here, we read the byte as an unsigned number: zero or a positive whole number.

Hexadecimal uses sixteen digits: 0 to 9, then A, B, C, D, E, and F for ten through fifteen. Each group of four bits fits into one hex digit, so two hex digits can describe a byte.

Binary 00101010, decimal 42, and hexadecimal 2A all describe the same value. The two extra zeroes at the start of the binary form keep all eight bit positions visible.

How much fits in one byte?

With all eight bits off, the number is 0. With all eight on, their values add up to 255. That gives us 256 different patterns, representing the unsigned numbers 0 through 255.

Processors use groups of bits like these to hold numbers, addresses, and instructions. First, let’s try a calculation with one byte: add one, and see what happens when the result no longer fits.