Skip to content

Reference chart

Binary, decimal and hex table

Binary counts in twos, decimal in tens and hexadecimal in sixteens. This table gives 0 to 15 in all three, the powers of two you'll meet in electronics, the byte values that come up again and again, and how to convert four bits at a time.

0 to 15

Hex uses 0–9, then A to F for 10 to 15. One hex digit is exactly four bits. The last column is the Gray code for the same number, where each step changes only one bit.

DecimalBinaryHexGray code
0000000000
1000110001
2001020011
3001130010
4010040110
5010150111
6011060101
7011170100
8100081100
9100191101
101010A1111
111011B1110
121100C1010
131101D1011
141110E1001
151111F1000

Powers of two

Each binary place is worth double the one before. These are the place values, and the number of patterns that many bits can make.

PowerDecimalHexWhere you'll meet it
2⁰10x1The lowest bit
2¹20x2Patterns in one bit: 0 or 1
2²40x4Patterns in two bits
2³80x8Patterns in three bits
2⁴160x10Patterns in four bits
2⁵320x20Patterns in five bits
2⁶640x40Patterns in six bits
2⁷1280x80The top bit of a byte
2⁸2560x100Patterns in a byte
2¹⁰10240x400A 10-bit ADC, like an Arduino Uno's
2¹²40960x1000A 12-bit ADC
2¹⁶65,5360x10000Patterns in 16 bits
2²⁴16,777,2160x1000000Colours with 8 bits each of red, green and blue
2³²4,294,967,2960x100000000Patterns in 32 bits

How far n bits count

n bits count from 0 to 2ⁿ − 1. A signed number gives up the top bit to say whether it's negative.

BitsCounts toIn hexSigned range
4150xF−8 to 7
82550xFF−128 to 127
1010230x3FF−512 to 511
1665,5350xFFFF−32,768 to 32,767
324,294,967,2950xFFFFFFFF−2,147,483,648 to 2,147,483,647

An Arduino Uno's int is 16 bits, so it tops out at 32,767; a long is 32 bits.

Common bytes

HexBinaryDecimalWhat it is
0x000000 00000Every bit off
0x010000 00011Only the lowest bit
0x0F0000 111115Low nibble: a mask that keeps the right four bits
0xF01111 0000240High nibble: a mask that keeps the left four bits
0x550101 010185Alternate bits, a test pattern
0xAA1010 1010170The other alternating pattern
0x7F0111 1111127The biggest signed byte
0x801000 0000128Only the top bit; −128 as a signed byte
0xFF1111 1111255Every bit on; −1 as a signed byte

Converting four bits at a time

Four bits make one hex digit, a nibble, so you never need to convert a long number in one go.

  • Hex to binary: write each digit as four bits. 0x3C is 3 and C, 0011 1100.
  • Binary to hex: group the bits in fours from the right, pad the left group with zeros, and swap each group for its digit. 1011010 is 0101 1010, 0x5A.
  • Hex to decimal: multiply each digit by its place, 1, 16, 256 and so on. 0xC8 is 12 × 16 + 8 = 200.
  • Decimal to hex: divide by 16. The answer is the left digit and the remainder the right: 200 ÷ 16 = 12 remainder 8, so C8.

In Arduino and C code, write hex as 0x3C and binary as 0b00111100. Both are the number 60.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“One or zero” is lesson 1 of 6 in Gate Grove, Digital Logic World 1. Free with an account. It’s open as soon as you sign up.

Or start from the very first lesson, no account needed

Work it out

The ideas behind it

Questions people ask

How do you convert binary to hex?

Split the bits into groups of four from the right, padding the left group with zeros, and swap each group for its hex digit. 1011010 becomes 0101 1010, which is 5 and A: 0x5A, or 90.

What is 0xFF in decimal?

255. FF is 15 × 16 + 15, and in binary it's 1111 1111: all eight bits of a byte on. It's the biggest number one byte can hold.

Why do programmers use hex instead of binary?

Each hex digit is exactly four bits, so a byte is always two hex digits. 0xB4 is far easier to read and type than 1011 0100, and you can still see the bits by converting each digit on its own.

What is a nibble?

Four bits: half a byte. One nibble is one hex digit, from 0 (0000) to F (1111). A byte has a high nibble, the left four bits, and a low nibble, the right four.

More charts