Converting Binary in your head =================================== by Riftor http://home.graffiti.net/riftor615/ =================================== Notes: I recommend viewing this with a fixed size font, so that the ASCII diagrams look ok. If your viewing in a text terminal that's fine, or if your using notepad or something Fixedsys will do :) Binary To Decimal ----------------- The easiest way of explaining is via the use of an example. Let's take the 8 bit binary number 10110100. Now each digit can be split into an allocation unit of a certain value, the powers of 2...(including 1 heh):- 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 etc. etc. but seeing as binary is read right to left then lets swap that around 4096, 2048, 1024, 512, 256, 128, 64, 32, 15, 6, 4, 2, 1 Each digit reading from right to left represents its corresponding value if it is 1. This can be easily showen using the "bins" explaination. For an 8 bit binary number we will need 8 bins, each with their respective values of powers of 2:- | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |___| |___| |___| |___| |___| |___| |___| |___| 128 64 32 16 8 4 2 1 All of which will add up to 255. Now with our binary number we can determine whether one of these bins is full or not. If the digit is 1 then the bucket is full, if its 0 it is empty. So for our number 10110100 this applies:- 1 0 1 1 0 1 0 0 |***| | | |***| |***| | | |***| | | | | |***| | | |***| |***| | | |***| | | | | |___| |___| |___| |___| |___| |___| |___| |___| 128 64 32 16 8 4 2 1 Where there is a 1 the value of that bin is represented, in this case there is 128, 32, 16 and 4. If you add all these together you will get the decimal value of the original binary number :) 128 + 32 + 16 + 4 = 180 If you want you can check this on your calculator heh, but its right! For 16bit and further numbers, just add more bins on the left with increasing powers of 2 [256,512, etc.etc] Decimal to Binary ----------------- The method is very similar, and is basically the reverse. Let's take the number 103. We need to start filling the bins from the left. Note: Also in this case the number is less than 255 so we know we only need 8 bins. The first bin (128) need not be full as the number is only 103, 128 doesn't go into 103 very well ;) 64 fits into 103 so lets fill that bin, leaving us with 39 (103-64) 32 fits into 39, fill that bin, leaves us with 7 16 doesn't fit into 7 8 doesn't fit into 7 4 fits into 7, fill that bin, leaves us with 3 2 fits into 3, fill that bin, leaves us with 1 1 fits into 1, fill that bin, and its all done :) 0 1 1 0 0 1 1 1 | | |***| |***| | | | | |***| |***| |***| | | |***| |***| | | | | |***| |***| |***| |___| |___| |___| |___| |___| |___| |___| |___| 128 64 32 16 8 4 2 1 Which means the value of 103 in binary is 01100111 :) Easy.... Once you practise a bit you can do it in your head without drawing waste recepticals rofl. Have fun. (shameless self promotion time...again...) http://home.graffiti.net/riftor615/