Sunday, November 15, 2009

Binary code

Hello lads!!! No time no see... Read this article to find out how to convert a number into a binary code or reverse...
First, let's say that binary code is a line of n numbers 1 or zero...
e.g. this 1001100...
If we take it logically 1 represents true and 0 false. If we had an electronic circuit, 1 means that electricity runs through it and 0 it's not...
So, let's go to the mathematical part now... Think about a calculator... How does it understand numbers and how does the calculations? With binary code... We are now going to see how the binary code represents a number leaving the engineering part out of this unit.
Think about a table of one column or row that has n cells... In that cells we put 1 (one) or 0 (zero). The function that returns the decimal (normal) number is working like this:
The first cell represents the 2^0, the second 2^1 the third 2^2.... It's like this:
the table:
If in a cell there's the number 1 we add 2^index and we add nothing if there's a zero.
Remember that in a line the index 0 represents the last number we see...
Let's look an example.
example 1. Find the decimal number that is represented by the binary : 1001110
In the above example we see a zero in the cell with index 0 so we ignore it or we multiply 2^0 with zero (it is the same thing, duh!).
Now if we have a number e.g 100 we do reverse work. we found the number power of 2 that is the closest to our number. In this case it is the number 64 i.e 2^6. 100-64=36. 32 is the closest, 32=2^5. 36-32=4. 4=2^2. So we are going to put the number 1 in the cells with index 6, 5 and 2. 100=1100100
You can practice making your own binary codes. To confirm your results you can download DBHC.exe from our blog.
P.S. If there are grammatical errors on the above article please let us know in order to fix it.
By Vasilis Nicolaou

No comments:

Post a Comment