Prev:
Hexadecimal Numbers
Next:
Hexadecimal and Binary
Numbers Quiz
Again, this section is probably past the basic level, but it pays to have some understanding of what binary is all about for the bitwise operator sections, which you can skip if you want.
In a nutshell: BINARY IS BASE 2.
So the only two digits you use to form binary numbers are 0 and 1.
I mentioned earlier that binary code is the lowest level language and that it's sometimes referred to as "machine code". This is because that the computer interprets a string of zeros and ones as a sequence of instructions: zero meaning an "off" state, one meaning an "on" state.
Anyway, back to binary numbers themselves, base 2 implies that you should know the powers of 2:
|
20 = 1 |
26 = 64 |
212 = 4096 |
- Any higher, and I must get my calculator :)
The procedure is very similar to the method used for hexadecimal numbers - the only difference is that you're using powers of 2 as opposed to 16.
Take the number 70 in decimal.
Find the highest power of 2 that goes into 70. Obviously, it's 64, so the highest power of 2 is 6, therefore you should expect 7 binary digits (or 7 BITS for short).
64 goes into 70 so the 1st bit is 1.
Now work out the remainder: 70 - 64 = 6.
Decreasing the power... how many times does 32 go into 6? Zero times, so the 2nd bit is 0.
Similarly, 16 and 8 don't go into 6, so the 3rd and 4th bits are both zeros.
4 goes into 6 once, so the 5th bit is 1. The remainder is 6 - 4 = 2.
2 goes into 2, so the 6th bit is also 1.
Now, there is no remainder, so the rest of the bits are all zeros - the 7th bit in this case.
Then we can conclude that 70 in decimal is expressed as 1000110 in binary.
Notice how you much of this you can do in your head, compared to hexadecimal. Because you're only working with zeros and ones - either a power of 2 goes into a number or not.
Converting negative decimals into binary won't be covered on this site. It'll be your homework to find out how to do this!
The reverse is easier. Take the binary number 100011011.
First write the bits in a column with the first bit at the top:
1
0
0
0
1
1
0
1
1
Then multiply the bottom with 20, the next one up with 21 and so on...
1*28 = 256
0*27 = 0
0*26 = 0
0*25 = 0
1*24 = 16
1*23 = 8
0*22 = 0
1*21 = 2
1*20 = 1
Add up the right hand side to get your answer:
256 + 16 + 8 + 2 + 1 = 283.
This sounds scary but it's not that bad.
Isn't it a pure coincidence that 16 is 24?! We can expand on this by saying that any number from 0 to F (0 to 15) can be expressed using 4 bits:
|
0 = 0000 |
4 = 0100 |
8 = 1000 |
C = 1100 |
Then take any hexadecimal number: AD say.
Replace each hex digit with the 4 bit equivalent:
A = 1010
D = 1101
So AD in hex is 10101101 in binary.
Check: 10*16 + 13*1 = 160 + 13 = 173.
1*27 = 128
0*26 = 0
1*25 = 32
0*24 = 0
128 + 32 = 160.
1*23 = 8
1*22 = 4
0*21 = 0
1*20 = 1
8 + 4 + 1 = 13.
160 + 13 = 173.
Note that precision is lost when you begin entering huge numbers!
Make sure you check to see if the number converts back to the original.
Prev:
Hexadecimal Numbers
Next:
Hexadecimal and Binary
Numbers Quiz
www.iota-six.co.uk
Copyright © 2001-2003
Unauthorized copying not permitted
Designed and Developed Using Macromedia Studio MX