Writing a Byte (Decimal to Binary)

IntermediateAbout 15 minData & binary

You can already read a byte. Now let's go the other way — turning an ordinary number into binary.

The Method: Divide by 2, Keep the Remainders

To convert a decimal number into binary, repeatedly divide it by 2. Each time, write down the remainder — it'll always be 0 or 1. Keep dividing the result until you reach 0. Then read the remainders from bottom to top. That's your binary number.

Grab a pencil and paper for this one — the examples below are much easier to follow if you work through them alongside us, not just read them.

Example 1: Converting 13

13 ÷ 2 = 6  remainder 1
 6 ÷ 2 = 3  remainder 0
 3 ÷ 2 = 1  remainder 1
 1 ÷ 2 = 0  remainder 1

Reading the remainders bottom to top: 1101

13÷ 2 =6remainder1
6÷ 2 =3remainder0
3÷ 2 =1remainder1
1÷ 2 =0remainder1

Read remainders bottom to top ↑

= 1101 in binary

Check it: 8 + 4 + 0 + 1 = 13. ✓

Example 2: Converting 41

41 ÷ 2 = 20  remainder 1
20 ÷ 2 = 10  remainder 0
10 ÷ 2 =  5  remainder 0
 5 ÷ 2 =  2  remainder 1
 2 ÷ 2 =  1  remainder 0
 1 ÷ 2 =  0  remainder 1

Bottom to top: 101001

41÷ 2 =20remainder1
20÷ 2 =10remainder0
10÷ 2 =5remainder0
5÷ 2 =2remainder1
2÷ 2 =1remainder0
1÷ 2 =0remainder1

Read remainders bottom to top ↑

= 101001 in binary

Check it: 32 + 8 + 1 = 41. ✓

The Easiest Mistake to Make

It's tempting to read the remainders top-to-bottom, in the order you wrote them. Don't — binary is built the other way around. The last remainder you calculate is actually the first digit of your answer. This trips almost everyone up the first time.

Don't Forget to Pad

Your result won't always be 8 digits. 41 converts to 101001 — only 6 digits. To write it as a full byte, add zeros to the FRONT (the left side) until you have 8 digits: 00101001.

Padding on the wrong side changes the number completely. Adding zeros to the end instead would give you 10100100 — a totally different value. Always pad on the left.

✓ Correct

00101001

Zeros added on the left

✗ Incorrect

10100100

Zeros added on the right — wrong

Try It Yourself

Practice

Can you convert decimal to binary like a pro? Ten numbers, one focused round. Let's find out.