Many of you have pondered in your spare time whether or not it is worth it to learn binary. Today, I’m here to tell you that if Flight of The Conchords can do it — you can too!
Let’s jump in
Here’s a simple case:
0000
This is an 8 bit representation of the number 0. Straight forward right? How do you think we would represent the number 1?
0001
Still with me? the last digit can only represent a 0 or 1. When it holds the 0 value, it passes on the value 0 to the computer. If it holds the value 1, it passes the value of 1 to the computer.
How do you suppose we do 2? Intuitively, we would just want to write a 2 where the 1 value in our previous example currently lives, but we can’t do this. At the core, computers can only understand 0′s and 1′s and thus the way that computers see a two is like this:
0010
In the case of 3 we just add what we’ve learned about 0,1,2 altogether.
0011
We keep the 2 from our previous example and add back the first position we talked about in the 0 and 1 case.
In the case of 4 we just remove all the 1′s we have and add a 1 to the next largest position:
0100
Now we can see a pattern, from 2 to 4 we had to remove the ones that were pre-existing for the odd numbers and move them to a ‘larger’ spot (the next one to the left).
As you’ve probably guessed, 8 is represented like this:
1000
Keep in mind that you’ll probably see 8 digits total when representing 8-bit numbers
0000 1000
With that representation we have a ‘byte’; 8 bits make up 1 byte. Therefore anything that is said to be ’32-bit’ is then 4 bytes. Interestingly enough, I’ve gotten this very question in an interview for a big company recently. Definitely good trivia to know if you want to be a programmer.
To represent binary numbers in your Chrome browsers:
1. Press command + shift + i
2. Then type in your number of interest (enclosed in parenthesis) then a toString function with the number 2 passed in the parenthesis.
i.e. (15).toString(2) should result in ’1111′ (aka 8+4+2+1)
Merry Coding,
Tony