// DIGITAL & ARDUINO · 3 MIN READ

Binary to Hex (and Decimal) Conversion Made Easy: 8-Bit Guide

Convert binary to decimal and hex in seconds: place values, the nibble trick, a 0–F table and examples like 0x20 = 32. Free bit flipper.

ON THIS PAGE
  1. Free binary and hex bit flipper
  2. Binary to decimal
  3. Decimal to binary
  4. Binary to hex: the nibble trick
  5. Hex to decimal
  6. Why microcontrollers use hex
  7. Prefixes you will see in code
  8. Frequently asked questions

Computers only store 1s and 0s, but long rows of bits are hard for humans to read. That's why programmers write numbers in hexadecimal. Once you see how both work, converting takes seconds — and code like PORTB = 0x20; suddenly makes sense.

Free binary and hex bit flipper

Flip the 8 bits and see the number in decimal, hex and binary — plus the C line to write it to a register:

⚡ LOADING THE CALCULATOR…

Free, no sign-up. Prefer a bigger screen? Open the Binary & hex bits calculator in the Lab →

Binary to decimal

Write the place values over the bits and add up the ones that are 1:

Place value1286432168421
Bits of 0b0010110100101101

32 + 8 + 4 + 1 = 45.

  • 8 bits (1 byte) go from 0 to 255.
  • 4 bits (1 nibble) go from 0 to 15.
  • 16 bits go up to 65,535.

Decimal to binary

Take away the biggest place value that fits, write a 1, and keep going:

200 → 128 fits (72 left) → 64 fits (8 left) → 32 no → 16 no → 8 fits (0 left) → 4, 2, 1 no → 1100 1000.

Binary to hex: the nibble trick

Hex has 16 digits: 0–9, then A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. One hex digit = exactly 4 bits, so:

  1. Split the byte into two nibbles: 1100 1000.
  2. Convert each nibble: 1100 = 12 = C, 1000 = 8 = 8.
  3. Result: 0xC8 (= 200).
BinaryHexDecimalBinaryHexDecimal
000000100088
000111100199
0010221010A10
0011331011B11
0100441100C12
0101551101D13
0110661110E14
0111771111F15

Hex to decimal

The left digit is worth 16 ×, the right digit 1 ×:

  • 0x20 = 2 × 16 + 0 = 32
  • 0xFF = 15 × 16 + 15 = 255
  • 0x7F = 7 × 16 + 15 = 127
  • 0xA5 = 10 × 16 + 5 = 165

Why microcontrollers use hex

A register is a row of 8 switches, and each bit controls one thing — for example, bit 5 of PORTB on an Arduino Uno is pin 13 (the built-in LED). Hex shows the bit pattern at a glance:

PORTB = 0x20;        // 0010 0000 → only bit 5 ON → pin 13 HIGH
PORTB |= (1 << 5);   // same bit, without touching the others

1 << 5 means "a 1 moved 5 places left" = 0b00100000 = 0x20 = 32. Shifting left by one doubles a number; shifting right halves it.

Prefixes you will see in code

  • 0b → binary (0b00100000)
  • 0x → hex (0x20)
  • no prefix → decimal (32)

All three are the same number to the chip.

Frequently asked questions

How do you convert binary to hex?

Split the binary number into groups of 4 bits from the right, and replace each group with its hex digit (0–9, A–F). 1010 1111 = 0xAF.

What is 0x20 in decimal?

  1. The 2 is in the sixteens place: 2 × 16 + 0 = 32. In binary it is 0010 0000.

Why is hex used instead of binary?

It is much shorter and each hex digit maps exactly to 4 bits, so programmers can read bit patterns quickly.

What is the largest number in 8 bits?

255, which is 1111 1111 in binary and 0xFF in hex.

Md Kaif · @iam.yourprofessor

Makes 30-second electronics lessons for total beginners — 231+ lessons, free video courses and interactive calculators on this site. Every guide is checked against real formulas and datasheets.

// WATCH · 30 SECONDS EACH

Watch it explained in 30 seconds

All lessons →
// KEEP LEARNING

More free guides

All guides →