Binary, Denary, Hexadecimal
Binary, Denary, Hexadecimal
Binary, Denary, Hexadecimal
10⁰ = 1
10¹ = 10
10² = 100
10³ = 1000
10⁴ = 10000
Using these headings you can write in a number, say 09032. Make sure that
you use all of the columns that you have digits for, starting at the right-most
column, which represents units. In this case 09032 has five digits, so you start
filling the table from the right, beginning with the 2 in the units column:
2⁰ = 1
2¹ = 2
2² = 4
2³ = 8
2⁴ = 16
2⁴ = 16 2³ = 8 2² = 4 2¹ = 2 2⁰ = 1
1 0 1 1 1
As we did with denary, we can write in a binary number, such as 10111.
Again, we have to make sure that we use the units (2⁰) column, with no gaps.
Now we can see that the number represented in binary as 10111 is made up
of one 16, zero 8s, one 4, one 2, and one 1. So, in denary, we have 16 + 4 +
2 + 1 = 23.
Try converting the following binary numbers into denary. Share your answers
and any problems you have in the comments section below:
1010
1001
10001
Converting numbers back the other way isn’t much more difficult.
If we wanted to convert the denary number 21 into binary, we could start out
with an empty table like this:
16 8 4 2 1
We need to look in each of the columns to see what needs to be placed there
using only ones and zeros. It’s easiest to do this by starting from the left: in
this case we would consider the number 21 and look at the table to see which
of the columns has the biggest number that is less than 21. This is 16, so our
first 1 would be in the 16 column.
16 8 4 2 1
1
Now, we still have 5 left (21 - 16 = 5) so we look to the right of the 16 column.
The next column along has an 8 in, which is too big to add on to our 16 and
would take us to 24. This means that we put a 0 in the 8 column and look at
the next column along. The next column is the 4 column which is useful (as it
is less than 5) and gets us closer to our target or 21, so we put a 1 in the 4
column.
Step 2, running total = 20
16 8 4 2 1
1 0 1
At this stage we have 16 + 4 = 20. We still need 1 to get to 21, so we put a 0
in the 2 column and a 1 in the 1 column. Now we have arrived at 21 and have
(1×16) + (0×8) + (1×4) + (0×2) + (1×1) = 21. This is shown in the table below:
16 8 4 2 1
1 0 1 0 1
Reading off from the table, we can see that 21 in binary is 10101.
Binary shifts
In a binary left shift we just shift the bits one column to the left. So, in the
image below you can see that the 0 in the 128 column disappears off the
table, the bit in the 64 column moves to the 128 column, the bit in the 32
column moves to the 64 column, and so on; we add a 0 in the now empty 1
column. This means that this example, which began as 00010110 (i.e. 16 + 4
+ 1 + 1 = 22), after being shifted one place to the left becomes 00101100 (i.e.
32 + 8 + 4 =44), which you will notice is 22 multiplied by 2.
So, if you left shift any binary number by 1 place it becomes 2 times bigger,
because binary is in base 2. This is exactly the same process as left shifting
denary numbers, except in denary numbers the left shift means multiply by
10. For example, if you left shifted 10 by one place it would become 10 times
bigger and would be 100.
Try a few examples yourself: 0010101, 11, 00110. You can check them by
converting to denary.
You don’t have to just shift by one bit, you could shift by 2 or more too,
effectively multiplying the numbers by powers of 2 each time. So a shift of
three places to the left would be the same as multiplying the number by 8 (i.e.
2×2×2).
Binary right shift
In a binary right shift we just shift the bits one column to the right to achieve
floor division. So, in the image below you can see that the bit in the 128
column moves to the 64 column, the bit in the 64 column moves to the 32
column and so on, until the bit in the 1 column disappears off the edge of the
table. In the example you can see that the binary number 00010100 (i.e. 16 +
4 = 20), after having shifted one place to the right, becomes 00001010 (i.e. 8
+ 2 =10), which you will notice is 20 divided by 2.
So, if you right shift any binary number by 1 place it becomes 2 times smaller,
because binary is in base 2. A binary shift of one place to the right is the same
as dividing by 2.
In the previous example the last digit in the 1 column was a 0, so we were not
concerned about what happened to that digit as it made no difference to the
size of the number. However, if we had a binary number which ended in a 1,
like 11010101 (which in denary is 128 + 64 + 16 + 4 + 1 = 213) in the example
below, what happens to the last 1 if it is right shifted? We mentioned earlier
that a binary right shift is the same as floor division, so only integer (or whole)
numbers are represented and remainders are ignored. That last 1 is a
remainder, so is ignored and simply does not appear in the answer.
You will see above that 11010101 right shifted becomes 01101010, so when
we convert this back to denary we see that we are effectively integer dividing
it (i.e. just looking at the whole number result), and we get that 213 integer
divided (or floor divided) by 2 is 106.
For the first two digits in the binary numbering system, addition is the same as
addition in denary, i.e. 0 + 0 = 0 and 1 + 0 = 1. But, as soon as we reach 1 + 1
we hit an issue. In denary this would be 2. But we don’t have the numeral 2 in
the binary base 2 numbering system.
So, 1 + 1 = 10.
Let’s try column addition with an eight-bit binary number. The process is the
same, carrying a 1 each time we add together two or three 1s, as shown in
the example below:
With binary, it is always sensible to convert back to denary to check for any
addition errors. So, with the eight-bit addition above, we can check the
addition as below:
128 64 32 16 8 4 2 1 Total
0 1 1 0 0 1 1 0 102
0 0 1 0 1 1 0 1 45
1 0 0 1 0 0 1 1 147
The first number converts to 102, the second to 45, and the answer to 147.
Indeed, the sum of 102 and 45 equals 147, so the binary addition is correct.
Hexadecimal Numbers
Although numbers are processed inside a computer as binary, that doesn’t
mean that we need to always represent these numbers as binary to humans.
1010 0101
A5
If you think A5 is easier and more convenient to remember and use, you now
understand why some binary is expressed in hexadecimal format. A5 is
actually the same value as 1010 0101; however, it is represented as
hexadecimal instead of binary.
128 64 32 16 8 4 2 1
1 0 1 0 1 0 0 1
128 + 32 + 8 + 1 = 169