Binary

From Qunet
Revision as of 09:48, 23 May 2022 by Mbyrd (talk | contribs) (Binary Addition)
Jump to: navigation, search


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: ­

Dec.jpg


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):

Bin.jpg

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:


TABLE B.1
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.


Put example here of dividing by 2, over and over, and keeping track of remainders, etc...

Binary to Decimal Conversion

ASCII

The computer needs to use binary strings to represent any characters, not just numerical values. How to rpresent the letter "w"? or the uppercase "W"? and so on... this was originally handled by using the American Staqndard for Information Interchange (ASCII, pronounced "ass-key, lol). So get yourself this table:

(Mark will make a table :)

Binary Addition

Adding binary numbers, by hand, is identical to the process one learns in gradeschool when adding decimal numbers. In decimal addition, if you add 5 + 5 then you get 10. When computing this sum, you get a digit of 0 and a carry digit of 1. If adding 6 + 6, then you get a digit of 2 with a carry digit of 1, and thus an answer of 12.

In binary, if you add 1 + 1, the sum is written as 10, because after summing 1 + 1 you get a digit of 0 and a carry of 1:



When adding binary numbers with multiple digits, the same approach is applied, as demonstrated in the following examples:


BinaryAdd.jpg


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!

TESTING SECTION

TABLE B.1
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

  1. Convert the following decimal numbers to binary:
  2. Convert the following binary numbers to decimal
  3. Add these binary numbers
  4. Challenge Questions
    1. Convert the following binary number into base 3:
    2. Foreword to the first edition
    3. Foreword to the second edition
  5. Eigenvalues and Eigenvectors
    1. About the author
    2. Foreword to the first edition
    3. Foreword to the second edition
  6. Tensor Products
    1. About the author
    2. Foreword to the first edition
    3. Foreword to the second edition