Skip to main content

Section 15.1 Binary Representations

Have you ever seen all of the "hacker" 01010110101010s in the movies? As you might know, this is called binary. While it’s not actually how hacking works, binary is still the base of all computing. Every word that you are reading right now was transmitted to your computer as a series of 1’s and 0’s. Although you won’t be typing 0’s and 1’s at a keyboard all day, binary is still useful to know.
Quick background: binary is a numbering system, just like decimal (the numbering system we normally use). Decimal uses the digits 0-9, but binary only uses the digits 0 and 1, which are called bits. In other words, binary is just a different way of counting.
Believe it or not, this is indirectly how you’ve been counting your entire life. For instance, in decimal numbering (base 10):
1023 (base 10) = (1 * 10^3) + (0 * 10^2) + (2 * 10^1) + (3 * 10^0)
There are even more numbering systems, like hexadecimal and octal, but you only need to understand binary for this course.
Binary deals with powers of two (hence the name), reading from right to left and starting at 0. If the bit is 0, it is "off" and the position is multiplied by 0; if the bit is 1, it is "on" and its position in the number is the exponent with 2 as the base. Binary numbering is also called base 2 because of that. For instance:
1000 (base 2) = (1 * 2^3) + (0 * 2^2) + (0 * 2^1) + (0 * 2^0) = 8
Converting decimal to binary: A quick way to convert decimal to binary is to find the largest factor of 2 that will go into the number, and concatenate 1 if it goes into the number; concatenate 0 if not. Subtract the number from the running total and repeat until we hit 0. For instance:
Example: Convert 78 to binary
1. If we think about all of our powers of 2, 2^7 = 128 is too large (128 > 78), so we know 2^6 is where we’ll start our number, and we need a 1 in that position. We now have: 1xxxxxx.
2. 78 - 64 = 14, which is our remainder from the last digit. 2^5 = 32 > 14, so we know 2^5 is a 0. We now have: 10xxxxx.
3. 78 - 64 = 14, which is our remainder from the last digit. 2^4 = 16 > 14, so we know 2^4 is a 0. We now have: 100xxxx.
4. 78 - 64 = 14, which is our remainder from the last digit. 2^3 = 8 < 14, so we know 2^3 is a 1 because it fits in! We now have: 1001xxx.
5. 78 - 64 - 8 = 6, which is our remainder from the last digit. 2^2 = 4 < 6, so we know 2^2 is a 1 because it fits in! We now have: 10011xx.
6. 78 - 64 - 8 - 4 = 2, which is our remainder from the last digit. 2^1 = 2 < 4, so we know 2^1 is a 1 because it fits in! We now have: 100111x.
7. 78 - 64 - 8 - 4 - 2 = 0, so we are done and can fill any remainders with a 0 bit.
Our final answer is: 1001110 (base 2)

Note 15.1.1.

Typically when we write binary, we’ll see our bits in groups of 4, because our binary sequences are normally some multiple of 4, like 8, 16, or 32. Because of this, we would add a leading zero and write our previous answer as: 0100 1110 (base 2).
Converting binary to decimal: As mentioned above, you can simply look at each bit, and add 2 to the power of its position if the bit is 1.
Like usual in math, there are a few different ways to arrive at one conclusion. These are not the only ways to do conversions. If these explanations don’t make sense to you, ask your instructor or Google for their explanation.
You have attempted of activities on this page.