Saturday, February 21, 2009

Binary

On Friday we learnt binary at school. I learnt conversion of decimals(as in numbers of base 10) to binary before on my own from a book, but never really understood the system until now. At school, they taught us to break the decimal into powers of 2 to convert. The method I learnt earlier was to subtract the largest possible power of 2 from the decimal. If that was possible, it was represented by 1. If not, it would be represented by 0.

Example:
15 - 8 = 7 ==> 1
7 - 4 = 3 ==> 1
3 - 2 = 1 ==> 1
1 - 1 = 0 ==> 1

Therefore 15 = 1111 in binary or base 2

17 - 16 = 1 ==> 1
1 is too large to subtract 8 ==> 0
1 is too large to subtract 4 ==> 0
1 is too large to subract 2 ==> 0
1 - 1 = 0 ==> 1

Therefore 17 = 10001 base 2.
Then, of course, I noticed 16, 8, 4, 2, 1 are all powers of 2(1 = 2 power of 0).
I must really be a bit of a Charlie Gordon to have not noticed this earlier.

3 comments:

  1. That's a good method for small numbers. It certainly gives insight into the process.

    For larger numbers you'll want to use the "divide by 2" method. It's not as clear in what's going on but it takes the trial and error out of it.

    Example, convert 14 to binary:
    14/2 = 7 remainder 0
    7/2 = 3 remainder 1
    3/2 = 1 remainder 1
    1/2 = 0 remainder 1

    Read the remainders backwards for the answer: 1110.

    You'll have to try it on bigger numbers to appreciate its advantage over the "subtract largest power of two" method.

    Rick Regan

    ReplyDelete
  2. Btw this method works with any base n. Just substitute divide by 2 with divide by n

    ReplyDelete
  3. Eh????? This is very confusing. Very, very, very confusing. Signed, your NXT building cousin

    ReplyDelete