Binary
Contents
Why We Need (why we use) Binary
Classical computers only have 2 states, or output options, and therefore can only use two symbols to represent those two states. More complicated questions are the combination of multiple yes and no questions in a series. Computers often use binary code, using just 0 and 1 to store the data. These are referred to as bits.
But here is an interesting shift of perspective: because "1" and "0" are just symbols you can read them as representing a different kind of thing. One important reading of the symbols is to read "1" as "Yes" and "0" as "No" to a given Yes/No question. A string of binary numbers such as "101" can thus be perceived as "Yes, No, Yes" to three Yes/No questions: e.g., "101" may stand for "Yes, it is Sunday; No, it is not raining; Yes, it is hot".
Binary expressions can also be used to represent numbers: e.g., 101 stands for the number five. So, when the computer stores "101" in its bit registers, you can think of the computer as storing the number five. This section will address how to convert binary numbers and the more common decimal numbers back and forth.
The binary number system is thus useful in computing and it is the way how computers represent and store a series of values or a numbers.
Numbering Systems
While numbers seem like absolutes, there are actually several different ways to write these values. One main difference in numbering systems is what we use as the base of the number. The decimal system uses a base 10, meaning that there are 10 symbols (0-9) that are used. Once you get past 9, you round up to a 1 in the tens position and start over at 0 in the ones position. A symbol in this instance is any single letter, number, or other symbol. There are many other base systems, including Base 16 (hexabase), Base 8 (octobase), and Base 2 (binary). Base 8 only uses 8 symbols (0-7) and binary only uses 2 symbols (0-1). Base 16 is a bit more complex as the 16 symbols that are used include the number 0-9 as well as the letters A-F. These base systems can still be used to represent the same numbers, and can be converted back and forth. Specifically converting between base 10 and base 2 (decimal to binary) is helpful.
The system you already understand very well is the decimal system, i.e. base 10, where we use 10 symbols (0,1,2,3,4,5,6,7,8,9). When keeping track of values larger than 9, multiple digits are necessary, where each digit represents a power of 10. For example, the value can be expanded to make this explicit:
Now consider the binary system, i.e. base 2, where we only use 2 symbols to describe any value (0 and 1). When keeping track of values larger than 1, multiple digits are necessary, where each digit represents a power of 2. For example, the value can be expanded to make this explicit (Note: the subscript "2" following the number means it is in base 2):
Decimal to Binary Conversion
Since we (as humans) have been trained to count and keep track of stuff using decimal symbols, and the computer needs to use binary symbols, it is useful to know how to convert between the two. For example, consider the decimal numerals 0 through 7, and the corresponding binary representation:
Binary | Decimal |
000 | 0 |
001 | 1 |
010 | 2 |
011 | 3 |
100 | 4 |
101 | 5 |
110 | 6 |
111 | 7 |
Table B1: Examples of Binary/Decimal Correspondence.
To convert a decimal number into a binary number, one can follow these steps:
- divide the decimal number by 2 to get the WHOLE number quotient. If the number is odd, you will be left with a remainder of 1; If the decimal number is even, then you will have a remainder of 0. The remainder is the resulting binary digit.
- Take the quotient from step 1 and repeat.
- Keep doing this until you get to a quotient of 0.
This procedure is shown in the following examples:
Division by 2 | Quotient | Remainder | Binary digit |
12 | 6 | 0 | 1st |
6 | 3 | 0 | 2nd |
3 | 1 | 1 | 3rd |
1 | 0 | 1 | 4th |
Division by 2 | Quotient | Remainder | Binary digit |
21 | 10 | 1 | 1st |
10 | 5 | 0 | 2nd |
5 | 2 | 1 | 3rd |
2 | 1 | 0 | 4th |
1 | 0 | 1 | 5th |
Binary to Decimal Conversion
To convert a binary number into the corresponding decimal number, recall that each digit in a binary number corresponds to to a power of 2. (see above, put a link here?)
For example, consider the binary number . Each digit corresponds to a power of 2 as shown in the following table:
Binary number | 1 | 0 | 1 | 1 | 1 |
power of 2 |
Binary Logic
When considering zero and one to be yes/no or true/false, there is an algebra (called Boolean algebra) that helps to designate how to combine these values. The main combinations are AND , OR , and NOT . The NOT gives , . The AND operation gives
The OR operation gives
One operation that we will use often is the exclusive OR, sometimes written as XOR. The symbol for the combination is and it gives the following values:
As we will see, these operations are performed very explicitly in quantum computing using matrices and vectors.
Conclusion (gearing up for logic gates)
We have just studied how to use binary expressions to represent numbers: e.g., 101 stands for the number five. So, when the computer stores "101" in its bit registers, you can think of the computer as storing the number five.
But here is an interesting shift of perspective: because "1" and "0" are just symbols and "101" is just a bunch of symbols, you can read them as representing a different kind of thing. One important reading of the symbols is to read "1" as "Yes" and "0" as "No" to a given Yes/No question, and "101" as "Yes, No, Yes" to three Yes/No questions: e.g., "101" may stand for "Yes, it is Sunday; No, it is not raining; Yes, it is hot".
Computers are good at manipulating binary numbers. This, combined with the "Yes/No" perspective, means that computers are also good at calculating answers to Yes/No questions: e.g., given "Yes, it is Sunday; No, it is not raining; Yes, it is hot", the computer can now calculate what the answer is to the question "Is it hot Sunday?" (the answer is Yes). This sort of "Yes/No" calculation is called "logic", and computers execute it by applying "logic gates" to bit registers. Indeed, that is how computers manipulate numbers --- computers execute operations such as addition of two numbers by actually applying logic gates and executing very complicated logic calculations!
Binary Logic
When considering zero and one to be yes/no or true/false, there is an algebra (called Boolean algebra) that helps to designate how to combine these values. The main combinations are AND , OR , and NOT . The NOT gives , . The AND operation gives
The OR operation gives
One operation that we will use often is the exclusive OR, sometimes written as XOR. The symbol for the combination is and it gives the following values:
As we will see, these operations are performed very explicitly in quantum computing using matrices and vectors.
Further Reading
Thomas Wong's book [49] is an excellent introductory resource for both classical and quantum computing.
TESTING SECTION
Binary | Decimal |
000 | 0 |
001 | 1 |
010 | 2 |
011 | 3 |
100 | 4 |
101 | 5 |
110 | 6 |
111 | 7 |
Table B1: Examples of Binary/Decimal Correspondence.
Exercises
- Convert the following decimal numbers to binary:
- Convert the following binary numbers to decimal
- Add these binary numbers
- Challenge Questions
- Convert the following binary number into base 3:
- Foreword to the first edition
- Foreword to the second edition
- Eigenvalues and Eigenvectors
- About the author
- Foreword to the first edition
- Foreword to the second edition
- Tensor Products
- About the author
- Foreword to the first edition
- Foreword to the second edition