Menu

Binary

Denary to Binary Conversion

Contents

  1. Denary to Binary: Place Value Method
  2. Denary to Binary: Repeated Division Method
  3. Nibbles in Binary

To turn a denary number into unsigned 8-bit binary, you can use the place-value method: compare the number with each binary place value from largest to smallest, deciding one bit at a time.

Write out the eight place values

Write 128, 64, 32, 16, 8, 4, 2 and 1 in a row. Each value is double the one on its right, and between them they cover every whole number from 0 to 255.

Place value1286432168421
Bit01011001
Amount left89252591110

Work from left to right

At each place, ask whether that place value fits into the amount you still have left.

  • If the place value is larger than the amount left, write 0 — nothing is taken away.
  • If it fits, write 1 and subtract that place value from the amount left.

Take 89. 128 is too big, so write 0. 64 fits, so write 1 and 89 − 64 = 25. 32 is too big: 0. 16 fits: 1, leaving 9. 8 fits: 1, leaving 1. Then 4 and 2 are too big: 0 and 0. Finally 1 fits: 1, leaving 0. Reading across gives 01011001.

The subtraction is what keeps the running total right. Writing a 1 without subtracting would set extra bits and push the total past the number you started with.

Once the amount left reaches zero, fill every remaining place to the right with 0 so that the answer is exactly eight bits, even when those bits add nothing.

The ends of the range

Eight bits give 256 different patterns, so an unsigned 8-bit number holds the values 0 to 255. Zero uses every bit at 0, so it is 00000000. 255 needs every place value: 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255, so all eight bits are 1 and it is 11111111. A denary number above 255 needs a ninth bit, so it cannot be stored in an unsigned 8-bit number at all.

Repeated division is a way of turning a denary number into binary by dividing by 2 again and again. You divide by 2, write down the remainder, and keep dividing the whole-number answer until it reaches 0.

Working through 45

Divide 45 by 2 and note the remainder — the 0 or 1 left over. Then divide the whole-number answer (the quotient) by 2 and note that remainder too. Stop as soon as the quotient reaches 0, because there is nothing left to halve.

DivisionQuotientRemainder
45 ÷ 2221
22 ÷ 2110
11 ÷ 251
5 ÷ 221
2 ÷ 210
1 ÷ 201

Read the remainders backwards

The remainders arrive the wrong way round: the first one you find is the least significant bit, which belongs on the far right of the answer. So read the list from the bottom upwards: 1 0 1 1 0 1. That gives 101101, and 32 + 8 + 4 + 1 = 45, which checks the answer is correct.

45 is divided by 2 repeatedly (45, 22, 11, 5, 2, 1) giving remainders 1, 0, 1, 1, 0, 1 until the quotient is 0; an arrow shows the remainders read from the bottom upwards as 101101, with the first remainder being the least significant bit. Below, it is padded with two leading zeros to 0010 1101 under the place values 128 to 1, and checked: 32 + 8 + 4 + 1 = 45.

Pad to exactly eight bits

101101 is only six bits long, so add leading zeros on the left until you have eight bits: 0010 1101. The zeros add no value, but they keep every bit sitting in the correct place value column. Smaller numbers need more padding — denary 5 comes out as 0000 0101 — while values of 128 or more already fill all eight places.

A byte can be split into two nibbles of four bits each. Each nibble is a small binary number in its own right, which makes a long pattern of 0s and 1s easier to read and convert.

The nibble on the left is the high nibble, holding the place values 128, 64, 32 and 16. The nibble on the right is the low nibble, holding 8, 4, 2 and 1. The place values still double from right to left across the whole byte — the split does not break the pattern.

Converting one nibble at a time

Take the denary number 97. In the high nibble, 128 is too big, so the first bit is 0. The next place value, 64, fits, so that bit is 1 and 97 − 64 = 33 is left. Next, 32 fits into 33, so that bit is 1 and 33 − 32 = 1 is left. The 16 is too big for the 1 remaining, so that bit is 0. The high nibble is 0110.

Now the low nibble, starting with the 1 left over. The place values 8, 4 and 2 are too big, so they are 0; the final place value, 1, fits exactly, so the last bit is 1. The low nibble is 0001. Putting them together gives 0110 0001.

Rules for the final answer

  • The answer must contain only the digits 0 and 1 — never a denary digit left over from your working.
  • Each nibble must be exactly four bits, so the full answer is always eight bits; keep any leading zeros in a nibble.
  • You may put a single space between the two nibbles, as in 1010 1100, to make the answer easier to read.

Writing the nibbles in the wrong order, low nibble first, gives a pattern that means a completely different number, so always build the high nibble on the left.

Also useful