Skip to content
Study Hall
Lesson 2 of 4Introduction to Computers
Unit 1 · Lesson 2 of 4

Binary, Decimal and Hexadecimal

Why computers count in twos, why programmers write in sixteens, and how to convert between all three without a calculator.

3 min read11 practice questionsInteractiveAsk AI about this →

Key things to remember

  1. 1Binary place values from the right: — doubling each time.
  2. 2An -bit number can represent different values, from to .
  3. 3One byte = 8 bits = values 0 to 255 = exactly two hex digits.
  4. 4Four bits = one hex digit, always. is the reason hex exists.
  5. 5Decimal → binary: divide by 2 repeatedly and read the remainders BOTTOM to TOP.
  6. 6Hex digits above 9: A=10, B=11, C=12, D=13, E=14, F=15.

A transistor is a switch. It is either conducting or it is not — on or off, high voltage or low. There is no reliable "a bit on", because component tolerances, temperature and electrical noise would make a ten-level signal unreadable. So computers count in a system with exactly two digits: binary. Everything else follows from that one hardware fact.

Place value is the whole trick

You already understand binary, because you already understand place value. In decimal, 305 means 3 hundreds, 0 tens, 5 ones — each column is worth ten times the one to its right, because there are ten digits. In binary there are two digits, so each column is worth twice the one to its right: 1, 2, 4, 8, 16, 32, 64, 128. Nothing else changes.

Binary is just place value with only two digits.1281640321161804120112ⁿ128 + 32 + 16 + 4 + 1 = 181Hex groups the same bits in fours:1011 → B0101 → 510110101₂ = 181₁₀ = B5₁₆
Fig 1One byte read three ways. The bits never change — only how we group them.

Binary to decimal

Write the place values above the bits, then add up only the places with a 1 underneath. That is the entire method, and it works for any width.

Add the columns that hold a 1; ignore the rest.

Decimal to binary

Two methods work, and you should know both. The subtraction method is faster once you know the powers of two by heart: take the largest power of 2 that fits, write a 1, subtract it, repeat. The division method is more mechanical and harder to get wrong: divide by 2 over and over, writing down each remainder, then read the remainders bottom to top.

Divide by 2QuotientRemainder
181 ÷ 2901
90 ÷ 2450
45 ÷ 2221
22 ÷ 2110
11 ÷ 251
5 ÷ 221
2 ÷ 210
1 ÷ 201
Read the remainder column from the BOTTOM up: 10110101.
The single most common error
Reading the remainders top-to-bottom instead of bottom-to-top. The last remainder you calculate is the most significant bit. Always check your answer by converting it back — if it does not give the number you started with, you read the column the wrong way.

Why hexadecimal exists

Binary is correct but unreadable — nobody can dictate 11010110 over the phone without a mistake. Hexadecimal (base 16) fixes this because 16 is 2⁴, so exactly four bits make exactly one hex digit, with no arithmetic across the boundary. A byte becomes two characters. A colour becomes six. A memory address becomes eight. That is why every error code, MAC address and colour code you will ever see is written in hex.

DecimalBinary (4-bit)Hex
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F
Memorize this table. Every hex conversion is four lookups, not a calculation.
Never go through decimal
To convert binary to hex, split into nibbles of four bits from the RIGHT and look each one up. 10110101 → 1011 0101 → B5. Converting to decimal first is slower and adds a place to make an arithmetic slip.
Loading interactive…
Flip bits and watch all three representations move together.

Notation

  • Binary: a subscript 2 (), a 0b prefix (0b1011), or the word stated — never assume.
  • Hexadecimal: a subscript 16, a 0x prefix (0xB5), or a # in colour codes (#FF8800).
  • Decimal: usually nothing, or a subscript 10 when the context is ambiguous.
  • 101 with no marking is genuinely ambiguous — it is 101 in decimal, 5 in binary, and 257 in hex.

Worked examples

Reveal one step at a time and try to beat it to the next line.

Example 1
Convert to decimal.
Example 2
Convert to 8-bit binary using the division method.
Example 3
Convert to binary and to decimal.
Example 4
How many different values can a 12-bit number represent, and what is the largest one?

Where marks get lost

  • Reading division-method remainders top-to-bottom instead of bottom-to-top, which reverses the whole answer.
  • Splitting a binary number into nibbles from the LEFT. Always group in fours starting from the right, padding the left with zeros.
  • Writing and then claiming the largest 8-bit value is 256. It is 255, because counting starts at 0.
  • Treating hex letters as variables. In , B is the digit 11, not an unknown.
  • Converting binary to hex by going through decimal — it works but wastes time and invites arithmetic errors.

Flashcards 9

Why do computers use binary?
Binary place values (8 bits)
How many values in n bits?
Largest 8-bit unsigned value
+ 5 more

Practice

1
Convert to decimal.
2
Convert to decimal.
3
Convert to 8-bit binary.
4
Convert to hexadecimal (two digits, no prefix).
5
How many distinct values can 6 bits represent?
6
Why is hexadecimal preferred over decimal for writing memory addresses?
7
What is the largest value that can be stored in 10 bits?
8
Order these values from smallest to largest.
  1. 1
  2. 2
  3. 3
  4. 4
9
Match each 4-bit group to its hex digit.
1010
1100
0111
1111
10
A colour is written #FF8800. What is the decimal value of the green channel (the middle two hex digits, 88)?
11
A student converts by dividing by 2 and writes the remainders as 1, 0, 1, 1, 0, 1 reading downwards. What is the correct binary answer?

Spot a mistake on this page? Let us know