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.
| Decimal | Binary | Hex | Gray code |
|---|---|---|---|
| 0 | 0000 | 0 | 0000 |
| 1 | 0001 | 1 | 0001 |
| 2 | 0010 | 2 | 0011 |
| 3 | 0011 | 3 | 0010 |
| 4 | 0100 | 4 | 0110 |
| 5 | 0101 | 5 | 0111 |
| 6 | 0110 | 6 | 0101 |
| 7 | 0111 | 7 | 0100 |
| 8 | 1000 | 8 | 1100 |
| 9 | 1001 | 9 | 1101 |
| 10 | 1010 | A | 1111 |
| 11 | 1011 | B | 1110 |
| 12 | 1100 | C | 1010 |
| 13 | 1101 | D | 1011 |
| 14 | 1110 | E | 1001 |
| 15 | 1111 | F | 1000 |
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.
| Power | Decimal | Hex | Where you'll meet it |
|---|---|---|---|
| 2⁰ | 1 | 0x1 | The lowest bit |
| 2¹ | 2 | 0x2 | Patterns in one bit: 0 or 1 |
| 2² | 4 | 0x4 | Patterns in two bits |
| 2³ | 8 | 0x8 | Patterns in three bits |
| 2⁴ | 16 | 0x10 | Patterns in four bits |
| 2⁵ | 32 | 0x20 | Patterns in five bits |
| 2⁶ | 64 | 0x40 | Patterns in six bits |
| 2⁷ | 128 | 0x80 | The top bit of a byte |
| 2⁸ | 256 | 0x100 | Patterns in a byte |
| 2¹⁰ | 1024 | 0x400 | A 10-bit ADC, like an Arduino Uno's |
| 2¹² | 4096 | 0x1000 | A 12-bit ADC |
| 2¹⁶ | 65,536 | 0x10000 | Patterns in 16 bits |
| 2²⁴ | 16,777,216 | 0x1000000 | Colours with 8 bits each of red, green and blue |
| 2³² | 4,294,967,296 | 0x100000000 | Patterns 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.
| Bits | Counts to | In hex | Signed range |
|---|---|---|---|
| 4 | 15 | 0xF | −8 to 7 |
| 8 | 255 | 0xFF | −128 to 127 |
| 10 | 1023 | 0x3FF | −512 to 511 |
| 16 | 65,535 | 0xFFFF | −32,768 to 32,767 |
| 32 | 4,294,967,295 | 0xFFFFFFFF | −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
| Hex | Binary | Decimal | What it is |
|---|---|---|---|
| 0x00 | 0000 0000 | 0 | Every bit off |
| 0x01 | 0000 0001 | 1 | Only the lowest bit |
| 0x0F | 0000 1111 | 15 | Low nibble: a mask that keeps the right four bits |
| 0xF0 | 1111 0000 | 240 | High nibble: a mask that keeps the left four bits |
| 0x55 | 0101 0101 | 85 | Alternate bits, a test pattern |
| 0xAA | 1010 1010 | 170 | The other alternating pattern |
| 0x7F | 0111 1111 | 127 | The biggest signed byte |
| 0x80 | 1000 0000 | 128 | Only the top bit; −128 as a signed byte |
| 0xFF | 1111 1111 | 255 | Every 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.
“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 neededWork 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
- Standard resistor values chartThe E12, E24 and E96 series, decade by decade, and which one to reach for.
- SMD resistor code chartTurn 472, 4702, 4R7 or 01C on a tiny resistor into ohms.
- LED forward voltage by colourEach colour's forward voltage, and how many LEDs fit in series on 5 V, 9 V or 12 V.
- Electronics unit prefixes and conversionsp, n, µ, m, k, M and G, conversion tables, and what 4k7 or 2n2 means.
- Capacitor code chartTurn 104, 473J or 2A into a value, a tolerance and a voltage rating.
- Common diodes chart1N4148, 1N4007, 1N5819 and the 1N47xx Zeners compared, and which one to use.
- Common transistors chartRatings, gain and pinouts for the BJTs and MOSFETs in every parts kit.
- Logic gate truth tablesAll seven gates' truth tables, how to write each one, and the chip numbers to buy.
- Arduino Uno pins and limitsWhich Uno pin does what, and how much current each pin and the whole board can give.
- AWG wire gauge chartAWG and mm² side by side, ohms per metre, and roughly how many amps each size takes.
- Battery voltage and capacity chartFull, nominal and flat voltages, typical mAh, and how full a lithium cell is from its voltage.
- Electronics formulas cheat sheetOhm's law to antenna length: every formula in the course, what it gives and where to learn it.
- Electronics glossaryFrom AC to Zener diode: the words of electronics, each in a sentence or two.