Pages

Monday, October 25, 2010

Translating Binary to Text

Contents
1. Introduction
2. The Binary System
3. Converting Binary to ASCII (Text)

Introduction:
We’ve all seen binary code. We’ve come to think of them as a bunch of ones and zeroes in long strings…
010010101010101001101011

But these ones and zeroes can also represent decimal numbers. First off, I will show you how to read these numbers as the decimal numbers we’re used to in our daily life. Then, I will show you how to use those numbers and your keypad to translate them into text. Note that your computer doesn’t use the decimal system, so technically, when it converts binary to text, it doesn’t go through the process I will show you. This is just a divertive way of explaining you how the binary system works.

The Binary System:
Here’s a simple example of binary:
10101

Let’s think of the example above as empty slots:
_ _ _ _ _

First off, you read binary from right-to-left. It’s just the way it’s designed. The first slot from the right represents a value of one, the second from the right a value of two, the third from the right a value of four, the fourth from the right a value of eight, the fifth from the right a value of sixteen, and the cycle continues by multiples of 2. This will never change.

By putting a 1 or a 0 in those slots you are either saying you want to corresponding value that’s attached to that slot or you don’t. A 1 means yes, and a 0 means no. For example, putting a zero in the first slot from the right, but a 1 in the second slot from the right means you want a two, but not a one:
_ _ _ 1 0

As such, the number above equals to a decimal value of two.

As an example, let’s say you want to represent eight in binary form. Well, thinking about the slots, you want the first slot to be 0 because you don’t want a one, you want the second slot to also be 0 because you don’t want a two, you want the third slot to also to be 0 because you don’t want a four, but you want the fifth slot to be 1 because you want a value of eight. As such, eight in binary form is:
1 0 0 0 (or simply 1000 without those underlines)

Now it is important to note that the amount of zeroes that precede the first value of one from the left is unimportant. So for example:
1 0 0 0 is the same as 0 0 0 1 0 0 0 (1000 = 000100)

To get it cleared up, here’s another example:
0 1 is the same as 1


Exercises: What do the following equal in decimal terms?
a) 100
b] 000100
c) 100000
d) 0010

Answers:
a) 4
b] 4
c) 32
d) 2

If you got the answers above right, then you pretty much understand the basics of binary.
Let’s now understand how to get the corresponding decimal values to the numbers which are not multiples of 2.

To get the total value of a binary number, add the values corresponding to each slot. So, for example, three in binary would be:
11

The above corresponds to three because if you add the total values of all the slots, that is to say a one from the slot to the right, and a two from the second slot to the right, then it equals three.

As another example, let’s say you want to represent 5 in binary terms. Then you would need a value of one to be added to a value of four, and you would not want a value of two:
101 [Reading from the right: 1(one) + 0(two) + 1(four) = five]

Here’s an additional example:
001011 [Reading from the right: 1(one) + 1(two) + 0(four) + 1(eight) + 0(sixteen) + 0(thirty-two) = eleven)



Exercises: What do the following equal in decimal terms?
a) 11011
b] 110
c) 010101
d) 10110

No comments: