Binary (Courtesy: CSCI E-1a, Harvard Extension School)
We use computers everyday
Inside a computer are “0s and 1s”
o Computers use the binary number system to represent info
How do computers represent info with just binary?
Consider the decimal number (what we human typically use) 123
o The rightmost column is the 1s column
o The middle, the 10s
o The leftmost, the 100s
100 10 1
1 2 3
o Thus we have 100 x 1 + 10 x 2 + 1 x 3 = 100 + 20 + 3 = 123
Inside a computer, the binary 000 would represent 0, just like in our human world!
o However, in this case we are dealing with binary so:
The right most column is the 1s place
The middle, the 2s
The leftmost, the 4s
4 2 1
0 0 0
o In the human world (decimal) we use powers of 10 for place values
100 = 1, 101 = 10, 102 = 100, 103 = 1000, etc.
o In the computer world (binary) we use powers of 2 for place values
20 = 1, 21 = 2, 22 = 4, 23 = 8, etc.
o The difference between decimal numbers and binary numbers is changing the
base
o For the binary number 000, we have 4 x 0 + 2 x 0 + 1 x 0 = 0 + 0 + 0 = 0!
Consider the binary number 001:
4 2 1
0 0 0
o We have 4 x 0 + 2 x 0 + 1 x 1 = 0 + 0 + 1 = 1
How do we represent the decimal number 2 in binary?
o We don’t need a 4, be we need a 2, and also no 1
4 2 1
0 1 0
o This gives us 4 x 0 + 2 x 1 + 1 x 0 = 0 + 2 + 0 = 2
Likewise, the number 3 would be:
4 2 1
0 1 1
o As we need a 2 and a 1
o Thus, 4 x 0 + 2 x 1 + 1 x 1 = 0 + 2 + 1 = 3
Similarly, 4 would be:
4 2 1
1 0 0
What about 7?
4 2 1
1 1 1
o Which yields 4 x 1 + 2 x 1 + 1 x 1 = 4 + 2 + 1 = 7
What about 8?
o We can’t count to 8 without another bit (binary digit)
We run into this in the real world too if we need a four-digit number vs
a 3-digit number
Start with the 1s, 10s, 100s place and add the 1000s
Here we’ll add the next power of 2, 8
8 4 2 1
1 0 0 0
8x1+4x0+2x0+1x0=8
Even though computers only use binary, they can count as high as humans can!
o They do it with a smaller vocabulary, just 1 and 0.
This is because it’s easier to represent two states in the physical world
If you think of one of these bits as being a light bulb:
0 is off
1 is on
Light bulbs just need electricity to turn on or off
Electricity is sufficient to turn a switch on or off
Inside a computer exists these switches called
transistors
Modern computers have billions!
Turned off represents 0
Turned on represents 1
Using these transistors we can store values, store data, compute, and do everything we
can with computers
So far all that we can represent is numbers
o A decision needs to be made on what pattern of 1s and 0s to represent letters,
words, and paragraphs
o All computers can store is 0s and 1s
o To represent letters, we need a mapping of 0s and 1s to characters
ASCII (American Standard Code for Information Interchange) does
this
65 -> A, 66 -> B, 67 -> C, etc.
97 -> a, 98 -> b, 99 -> c, etc.
ASCII also has mapping for punctuation symbols
o Programs like notepad, textedit, and MicroSoft Word decide whether to
display patterns of bits as letters or words
Computers only store 0s and 1s, but the programs interpret those bits in
a certain way
For example, if MicroSoft word sees a pattern of buts
representing the number 65, it will interpret that as “A”
o ASCII is limited
Original ASCII is 7 bits, thus giving 128 characters
Extended ASCII is 8 bits, yielding 256 characters
Many symbols are not represented
o UNICODE is a bigger set of characters that includes written languages other
than English and even emoji! 😲
All are still represented by a pattern of bits
Consider this pattern of bits: 01001000 01001001
o 16 bits or 2 bytes (1 byte = 8 bits)
128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1
0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 1
1 x 64 + 1 x 8 1 x 64 + 1 x 8 + 1 x 1
72 73
H I
o Using ASCII we get the word “HI”
How a Computer Keyboard Works
(https://computer.howstuffworks.com/keyboard2.htm)
A voltage is passed through the column connectors (one at a time) of the keyboard
matrix scanner. When a key is pressed on a keyboard, it presses a switch, completing
the circuit and allowing a tiny amount of current to flow through.
When the keyboard controller finds a circuit that is closed, it reads the location of that
circuit on the key matrix and looks for the corresponding character in the character
map in its read-only memory (ROM). A character map is basically a comparison chart
or lookup table. The ASCII value of that character is then sent to the processor.
How an Optical Mouse Works
The LED installed at the bottom of the mouse emits a bright light in the downward direction.
Since a mouse is usually used on plain surfaces, the light bounces back from the surface and
enters a photocell which is also mounted on the bottom, almost next to the LED. This photocell
has a frontal lens that magnifies any light reaching it. As you move the mouse around, the
pattern of the reflected beam changes; this is then used by the light-detector chip to figure out
how and in which direction you’re moving the mouse.