The Mudcat Café TM
Thread #115539   Message #2474878
Posted By: JohnInKansas
24-Oct-08 - 10:44 AM
Thread Name: Tech: converting binary data to ASCII
Subject: RE: Tech: converting binary data to ASCII
If the "places" in the binary are number are numbered (in decimal) from least significant to most significant, then the "bit-value" in each place contributes (bit-value)*2n-1, where n is of course the "place-value" (i.e. the column) for the bit.

In the first (least significant) place,
n = 1,
n-1 = 0,
20 = 1,
so if the bit-value is zero,
0 * 1 = 0,
and if it's 1,
1 * 1 = 1.

For the next bit,
n = 2,
n-1 = 1,
21 = 2,
so if the bit-value is zero, again
0 * 2 = 0,
and if it's 1,
1 * 2 = 2.

Since 0 x (anything) is zero, you only have to look at the places with "1"s in them.

A 1 in first place adds             1
A 1 in second place adds            2
A 1 in third place adds             4
A 1 in fourth place adds            8
A 1 in fifth place adds            16
A 1 in sixth place adds            32
A 1 in seventh place adds          64
A 1 in eighth place adds          128

If you simply strike out the "places" where there are zeros, and add the above values for all the "places" where there are ones, the total is the value of the binary.

Thus the binary 10101010 is 128+32+8+2 = 170 in decimal notation.
And the binary 01010101 is 64+16+4+1 = 85 in decimal notation.
And binary 01101101 is 64+32+8+4+1 = 109 in decimal notation.

Really simple, once you get the hang of it.

Someone will now notice that the binary 11111111 has decimal value 255, and we said that an 8-bit binary can have 256 different vales. Before someone pops a fuse, note that one of the 256 values is ZERO.

With 8 bits, one has 256 "values" and with 256 "values" one can only count from zero to 255. Unless, as has been done by some of the computer wizards, you "shift" the results to make 00000000=256, (an implied "flip of the next left bit" to 1 - in the column with column-value 256, even if there is no such column, which when added to 00000000 gives decimal 256) so that you can count from 1 to 256, but can't sell a zero on the open market. It has been done both ways, and people have argued about which is right since about day 1

(or maybe it was day 0).

John