Wednesday, August 6, 2008

Understanding binary code

[My apologies -- but this article doesn't want to keep its formatting]

Mr. Farmer’s solution of the IKLP long code produced two lines of binary code: line 7 and line 55, which he said combined to form the familiar smiley face (<.

Line 7 solution: 1010-101-11-0 converted to the < symbol.
Line 55 solution: 0010-100-01-0 converted to the ( open parenthesis.

No one on the forum challenged his conversion, and since I had absolutely no knowledge of binary code, I assumed it was correct. In the meantime, I've done some research. The best tutorial on binary code I have found is Translating Binary into Text.

Basically, binary text is read from right to left, not from left to right as we read words or numbers. Each position in the binary has a fixed valued. A 1 in that position means the value is present; and a 0 in that position means it is not. Starting from the right, the first position has a value of 1, the second position a value of 2, the third position a value of 4, the fourth position a value of 8, the fifth position, a value of 16 – and so on, multiplying by two to get each successive value.

01 as binary code represents the decimal 1 because 1 signifies that the value 1 is present, and the 0 signifies that the value 2 is not present. 001 also represents the number 1, as does 0001.

Here are more examples:

  • a) 100 = 4; reading from right to left, the 1 is not present, the 2 is not present, but the 4 is present.
  • 000100 also = 4 – the leading left zeroes are meaningless
  • 100000 = 32; reading from right to left, the 1 is not present, the 2 is not present, the 4 is not present, the 8 is not present, the 16 is not present, the 32 is present
  • 0010 = 2; reading from right to left, the 1 is not present, the 2 is present, and the leading left zeroes are meaningless

Now for more examples, which require adding the present values to determine the conversion:

  • 11011 = 27; reading from right to left, the 1 is present, the 2 is present, the 4 is not present, the 8 is present, the 16 is present, so you add 1+2+8+16=27
  • 110 = 6; reading from right to left, the 1 is not present, the 2 is present, the 4 is present, so you add 2+4=6
  • 010101 = 21; reading from right to left, the 1 is present, the 4 is present, the 16 is present, so you add 1+4+16=21.
  • 10110 = 22; reading from right to left, the 2 is present, the 4 is present, and the 16 is present, so you add 2+4+16=22.

Here is one way of converting decimal to binary. (source)

Example 1: Convert 98 from decimal to binary.

1) Divide 98 by 2, making note of the remainder. Continue dividing quotients by 2, making note of the remainders. Also note the star (*) beside the last remainder.

Division---->Remainder, R
98 / 2 = 49----->R=0
49 / 2 = 24----->R=1
24 / 2 = 12----->R=0
12 / 2 = 6------>R=0
6 / 2 = 3------->R=0
3 / 2 = 1------->R=1
1 / 2 = 0------->R=1*

2) The sequence of remainders going up gives the answer. Starting from 1*, we have 1100010. Therefore, 98 in decimal is 1100010 in binary.

To check your answer, read from the right: 1 is not present, 2 is present, 4 is not present, 8 is not present, 16 is not present, 32 is present, 64 is present. Add 2+32+64=98.

Fortunately, we have converter sites on the internet, where you simply plug your number in and it produces the binary code, or vice versa.

Back to Mr. Farmer’s solution. I went to a couple of these converter sites and plugged in his translation of his binary code solutions for lines 7 and 55. (livephysics, roubaixinteractive, snarkles)

Line 7 solution:
1010-101-11-0 which Mr. Farmer translated to <.

00111100 which, according to the converter sites, is the binary code for <

Reading from right to left, they clearly don’t match up.

Line 55 solution:

0010-100-01-0 which Mr. Farmer translated to the open parenthesis (.

00101000 which is the binary code for the ( according to the converter sites.

Reading from right to left, the codes do not match. The binary code is embedded in Mr. Farmer’s solution, but does that count, since binary code is read from right to left?

Perhaps Mr. Farmer can explain why his solutions don’t match the binary codes produced by the converters.

-------------------------

Checking our work by reversing the process:

The binary code 111100 converts to a decimal value of 60, which is the decimal value for <: reading from right to left, the 1 is not present, the 2 is not present, the 4 is present, the 8 is present, the 16 is present, and the 32 is present. Add 4+8+16+32=60.

The binary code 101000 converts to a decimal value of 40, which is the decimal value for ( open parenthesis: reading from right to left, the 1 is not present, the 2 is not present, the 4 is not present, the 8 is present, the 16 is not present, the 32 is present. Add 8+32=40.

Source for ASCII

3 comments:

Anonymous said...

Thank you so much for this. You explained it so even I could understand it. Why didn't Farmer?

Anonymous said...

There are many encoding schemes for computer characters, it is quite possible the code is from another encoding scheme other than the more common ASCII.

Anonymous said...

There are many encoding schemes for computer characters, it is quite possible the code is from another encoding scheme other than the more common ASCII