OK, so now we have a vague understanding of binary notation. The next question is; do we have an understandable, programmable way of getting binary numbers from decimal numbers? The answer is yes! Lets start with 710; all you have to do is keep dividing by 2 until there is no number left. I'll explain, the first divide by 2, is 3 in decimal. This gives us a remainder of 110; there are only two numbers a remainder can be in binary or when dividing by two, 1 or 0. This is a powerful piece of information because it makes all your calculations much easier. When you divide to get binary, you only record the remainders, and you only operate (divide) on the result of your division. This will become clear in a moment, this table will help you see how to convert 7 in decimal to 0111 in binary.
|Divide:||7/2 = 3||3/2 = 1||1/2 = 0|
|Remainder:||Remainder = 1||Remainder = 1||Remainder = 1|
You than flip the result and that gives you 111, or 0111 with a zero on the left to pad the number to 4 bits.
Now lets try converting 910 to binary.
|Divide:||9/2 = 4||4/2 = 2||2/2 = 1||1/2 = 0|
|Remainder:||Remainder = 1||Remainder = 0||Remainder = 0||Remainder = 1|
Notice that each time we divide (9/2 gives us 4, then we divide 4 by 2, that gives us 2, then 2/2 give us 1 and so forth) we only record the remainders. Then, we flip the results, and there is our number 10012. Up until now our numbers have been symmetrical so the flip has not been apparent. Lets try one that is not symmetrical:
Lets try 2310
|Divide:||23/2 = 11||11/2 = 5||5/2 = 2||2/2 = 1||1/2 = 0|
|Remainder:||Remainder = 1||Remainder = 1||Remainder = 1||Remainder = 0||Remainder = 1|
The answer is 101112. Now it matters which way we read the number, 11101 is a very different number than 10111. We always start reading the binary number from the last operation we worked on (bottom to top). That's it, that is the hardest part, it's all down hill from here!
Converting binary numbers to decimal notation is as easy as adding. The 8-bit number 000100112 for example.
Just add where you see a 1. (16 + 2 + 1 = 19)
Just to review, for any number denoted a, where a is any non-zero number:
|Always = 1||Always = a (the value of a)||Always = a * a||Always = a * a * a||Always = a * a * a * a||Always = a * a ... n Times|