The Power of Binary
âThere are 10 types of people in the world: those who understand binary and those who donât.â
â The most overused binary joke in existence.
As Iâve mentioned in previous posts, computers use the binary system (base 2) to store data in the form of numerical values. Alone, a single bit, or binary digit, can only store two values. When combined, each additional bit adds a power of two, and therefore many additional values that can be represented. Though you may not think it at first, any decimal number (base 10) may be represented in binary.
Hereâs a binary number. To convert it to decimal, use the following pattern with powers of two starting with the least significant digit (convert from right to left):
1001101
2^0 * 1 = 1
2^1 * 0 = 0
2^2 * 1 = 4
2^3 * 1 = 9
2^4 * 0 = 0
2^5 * 0 = 0
2^6 * 1 = 64
TOTAL = 78
To convert a decimal number to binary, divide the number by two. The remainder is the least significant digit. Continue the pattern using the result of the integer division until the quotient equals 0:
62
62 / 2 = 31 R0
31 / 2 = 15 R1
15 / 2 = 7 R1
7 / 2 = 3 R1
3 / 2 = 1 R1
1 / 2 = 0 R1
RESULT = 111110
An astute observer might say, âBut what about negative numbers? I can have negatives in my Excel spreadsheet.â Well, Sherlock, thereâs something out there called twoâs compliment that resolves your conundrum; twoâs compliment trades the most significant digitâs numeric representation ability for a flag to represent a negative number:
11111110
If you use the rules above, you may expect this value to be 254, but with twoâs complement, it represents -2. Values that are assigned the twoâs compliment property are known as signed integers, and those that use the additional bit for values are known as unsigned integers respectively.
For all of the aspiring programmers out there, here are the minimum and maximum values for each standardized data type, unsigned and signed:
Byte (8 bits): 0 to 255 / -128 to 127
Short (16 bits): 0 to 65,535 / -32,768 to 32,767
Integer (32 bits): 0 to 4,294,967,295 / -2,147,483,648 to 2,147,483,647
Long (64 bits): 0 to 18,446,744,073,709,551,615 / -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Also, people donât actually code in binary. That would take about ~011110100001001000000 years.
Chase Garner â16
(image source: pcmerch.com)












