How To Calculate Binary Code

December 12, 2008 aznhottie604

When you learn most types of computer programming, you will touch upon the subject of binary numbers. Although this is a simple concept once explained, it is not always obvious how to read them. To understand binary numbers, let’s first look at our normal system of base 10 numbers.

Let’s take the number 345 for example. This is a three digit number. We know that the farthest right number, 5, represents the 1’s column, and there are 5 ones. The next number from the right, the 4, represents the 10’s column. There are 4 clicks in the 10s column, which we interpret as forty. Finally, the third column that contains the 3 represents the 100s column, and we know it to be three hundred.

Binary works in the same way. Each column represents a value, and when you have enough you move to the next column. The difference is that in our base 10 system we need to have 10 before we move to the next column. We can have any value 0-9, but once it goes above that, we add a column. In base two, you can only have 0 or 1 before moving on to the next column.

The number one is represented as 1 in both base ten and binary, so let’s move on to the number two. In base ten this is represented as a 2, however in binary we can only have a 0 or a 1 before moving on to the next column. The number 2 is written as 10. This means 1 in the 2s column and 0 in the 1s column.

Let’s take a look at the number three. Obviously in base ten it is written as 3. In base two (binary) it is written as 11. This means a 1 in the 2s column and a 1 in the 1s column. 2+1 = 3.

Each slot represents a value that is double the last value. The chart on this page helps to demonstrate this. The values of slots, starting on the right are 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, etc.

Now that we know how binary works, reading it is simply a matter of doing some simple math. Let’s try a few:

1001

Since we know the value’ots each of these sls represent, then we know this number represents 8 + 0 + 0 + 1. In base ten this would be the number 9.

11011

Again we can calculate what this is in base ten by adding the values of each slot. In this case it would be 16 + 8 + 0 + 2 + 1. This would be the number 27.

To convert decimal to binary is also very simple, you simply divide the decimal value by 2 and then write down the remainder, repeat this process until you cannot divide by 2 anymore, for example let’s take the decimal value 157:

157 ÷ 2 = 78 with a remainder of 1
78 ÷ 2 = 39
with a remainder of 0
39 ÷ 2 = 19
with a remainder of 1
19 ÷ 2 = 9
with a remainder of 1
9 ÷ 2 = 4
with a remainder of 1
4 ÷ 2 = 2
with a remainder of 0
2 ÷ 2 = 1
with a remainder of 0
1 ÷ 2 = 0
with a remainder of 1<— to convert write this remainder first.


Entry Filed under: Uncategorized

Leave a Comment

Required

Required, hidden



Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to comments via RSS Feed

Pages

Categories

Calendar

December 2008
M T W T F S S
« Nov   Jan »
1234567
891011121314
15161718192021
22232425262728
293031