Binary Numbers
02
There are only 10 types of people in the world.
Those who understand binary and those who don't.
One of the important principles of computer science is that computers use binary sequences: i.e., sequences of 0s and 1s, to represent all data. That means our photographs, videos, text messages, mobile apps, Word documents, and numerical quantities are all represented as sequences of bits.
In this unit we want to focus on the binary number system: i.e., using sequences of 0s and 1s to represent numbers. The binary number system is very similar to our decimal number system. But whereas the decimal system uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, to represent numbers, the binary system uses only two digits: 0 and 1.
The reason computers use the binary system is because its two digits, 0 and 1, are easily represented in electronic devices, where the 0 could be represented by "off" and the 1 by "on". Or the 0 could be represented by low voltage and the 1 by high voltage. A bit is the smallest unit of binary information. A bit can be either 0 or 1. So, in one sense, because it uses only 2 digits, whereas the decimal system uses ten digits, the binary number system is even simpler that our decimal system.
Amazingly, by combining 0s and 1s in various combinations, we can represent all of the data and information that computers use and process.
Technical Terminology
binary sequence - A binary sequence is a sequence of 0 and 1s
bit - A bit is a single binary digit, either 0 or 1. It is the smallest unit of data in a computer. Short for binary digit
binary number system - The binary number system is a number system in which all numbers are represented in terms of only 2 binary digits, 0 and 1
base - The base of a number system refers to the number of distinct digits or symbols used to represent numbers in that system. Our decimal system is base-10 because it uses ten digits, 0 through 9
positional number system - In a positional number system, such as our decimal system, the value of a digit in a number depends on its place. For example, in the decimal number 545, the leftmost '5' represents 500 because it occurs in the hundreds place, but the rightmost '5' represents 5 because it occurs in the ones place: in this case places are based on powers of ten.
Converting Binary to Decimal
As you saw in the video, the binary number system is a positional number system The value of a particular digit depends on its place.
The place values for the binary system are the 1s place, the 2s place, the 4s place, the 8s place, the 16s place, and so on (powers of two). Contrast that with the place values for the decimal system: the 1s place, the 10s, place, the 100s place, and so on (powers of ten).
To figure out the decimal value of a binary number, we add up the powers of two of all the places that contain a 1.
Write the binary number, leaving some space between the digits. For example:
1 0 1 0 1
Starting from the right hand side of the number, write the place value of each binary digit in the number under the digits, starting with 1 then 2, then 4, then 8, and so on, doubling the place value each time. For example:
1 0 1 0 1
16 8 4 2 1 (Place values)
Add up the powers of two of every place value that is a 1. For this example, that would give 16 + 4 + 1, which is 21.
1 0 1 0 1
16 8 4 2 1 (Decimal value: 16 + 4 + 1 = 21
Converting Decimal to Binary
You can a similar algorithm to convert decimal numbers into binary. For example, here's the algorithm as applied to the decimal number 25:
Starting on the right, write the place values of powers of two, starting at 1, then 2, then 4, then 8,and so on.
32 16 8 4 2 1
Find the largest power of two that will go into the number and place a 1 under it. For example, for 25, the largest power of 2 that goes into it is 16:
32 16 8 4 2 1
1
Subtract that power of two from the number, getting a new value. In this case, 25 - 16 is 9.
Repeat step 2 and 3 until you get to 0. So for this example, we would next get an 8 and subtract. That gives a new value of 1. And the final power of two would then be a 1, and subtracting that gives a remainder of 0 and we are done. Put 1s under each power of two that was subtracted:
32 16 8 4 2 1
1 1 1
Put a 0 under all the other places to produce the binary number. In our example, 25, this gives, 11001 or 0001 1001. (note, we can ignore preceding 0s, or usually we write binary in in groups of 4 bits: half-byte or nibble)
32 16 8 4 2 1
0 1 1 0 0 1
Still Curious?
Adding in binary has the same carry rules as normal adding in decimal, except that the carry is for each power of two and not power of ten. See an example to the right.
One problem with binary numbers is that it takes lots of digits to represent relatively small numbers. For example, a number like 1 million, which really isn’t very big these days, would requires 20 binary digits: 11110100001001000000.
There are lots of online video lessons about number systems. You can search for "binary numbers" or "hexadecimal numbers" or "number systems". Here's a Khan Academy video on binary numbers.
Going even further: each character representing letters etc. are given a number in ASCII and Unicode, and these numbers can be converted into binary and used in computers