Menu

Memory & Storage

Binary to Denary Conversion

Contents

  1. Converting between Binary and Denary
  2. Padding Binary Numbers
  3. Checking Binary to Denary Answers

Computers store every number as a pattern of bits, so binary to denary conversion turns a stored value into a number people can read. You work out what each bit is worth, then add up the columns that are switched on.

Write the place values above the bits

In binary each column is worth twice the column on its right, so an 8-bit number uses the place values 128, 64, 32, 16, 8, 4, 2 and 1. Write those eight values in a row, then write the binary number underneath with its rightmost bit lined up under the 1. That bit is always worth 1, and the place values grow as you move left. A shorter binary number lines up the same way, so the six-bit number 101101 sits under 32, 16, 8, 4, 2 and 1, giving 32 + 8 + 4 + 1 = 45.

Place value1286432168421
Bit10011010
Count it?128ignoreignore168ignore2ignore

Add the place values of the 1s

Work along the columns. A 1 means the column is switched on, so its place value counts. A 0 means the column is switched off, so ignore that place value completely: it adds nothing to the total, and you never add the digit 0 itself. The denary value is the total of the place values you kept, which for the number in the table is 128 + 16 + 8 + 2 = 154.

Show the working

Write out the place values and the addition instead of doing it in your head. A tidy sum is easy to check, because you can see at a glance which columns you counted, and a slip such as counting 64 where the column is really worth 32 stands out immediately. Add the place values a second time in a different order as a final check.

Binary numbers can be any length from 1 to 8 bits, but the place values 128, 64, 32, 16, 8, 4, 2 and 1 only give the right total when each bit sits in the correct column. A short number has to be padded — filled out with extra zeros on the left — before you convert it.

Padding and lining up from the right

To pad a number, add zeros to the left-hand end until it is exactly 8 bits long. Padding never changes the value, because each new zero sits in a column whose place value you never add in. So 101101 becomes 00101101, and it is still the same number.

Once the number is 8 bits, the least significant bit (the rightmost bit) sits under the place value 1, and every bit to its left moves one place value up: 2, 4, 8 and so on. Bits are always lined up from the right, never from the left, because a bit is worth whatever place value it lands on when you count back from that right-hand 1. A short number lined up from the left lands on the big place values and comes out far too large.

Worked example

A 6-bit reading from a greenhouse light sensor arrives as 101101. Convert it to denary. It has 6 bits, so pad it to 00101101 and write the place values above it:

1286432168421
00101101

The 1s are in the 32, 8, 4 and 1 columns, so the value is 32 + 8 + 4 + 1 = 45. Pushed up against the 128 column instead, those same bits would land on 128, 32, 16 and 4 and give 180.

That is why the leftmost bit of a short number is not worth 128: its place value depends on how many bits the number has. Only a full 8-bit number has 128 in its most significant bit position, and for 00101101 that column holds a 0 anyway.

Binary values are usually written as a full 8 bits, so the leading zeros you added stay in the answer.

Once you have converted a binary number to denary, the two end bits let you catch a slip in seconds: the most significant bit on the left and the least significant bit on the right.

What the end bits tell you

In an 8-bit number the most significant bit sits in the 128 column. When it is 1, that column adds 128 to the total, so the result cannot be below 128. When it is 0, the column contributes nothing and the rest add up to 127 at most. The least significant bit is worth 1, and every other place value is even, so the total is odd exactly when that bit is 1 and even when it is 0.

MSBLSBWhat your answer must be
00127 or less, and even
01127 or less, and odd
10128 or more, and even
11128 or more, and odd

Testing an answer

Take 01010110. Its MSB is 0, so the answer must be 127 or less, and its LSB is 0, so it must be even. Adding the columns holding a 1 gives 64 + 16 + 4 + 2 = 86, which fits both. An answer of 186 fails at once, because a number starting with 0 can never reach 128, and 91 fails because a number ending in 0 is never odd. Either mistake sends you back to the place values. A range check catches the rest: an 8-bit pattern holds values from 0 to 255 only, so an answer outside that range is impossible too.

Converting back

The strongest check is to rebuild the pattern from your denary answer. Take 10101101: MSB 1 means 128 or more, LSB 1 means odd, and 128 + 32 + 8 + 4 + 1 = 173 fits both. Now build 173 from the place values: 173 − 128 = 45, 45 − 32 = 13, 13 − 8 = 5, 5 − 4 = 1, 1 − 1 = 0. That puts 1s in the 128, 32, 8, 4 and 1 columns and 0s in the rest, giving 10101101 — the pattern you started with. If the rebuilt pattern differs, the original conversion was wrong.

Also useful