How Computers Think: Binary, Decimal and Hexadecimal

Download Report

Transcript How Computers Think: Binary, Decimal and Hexadecimal

How Computers Think:
Binary, Decimal and Hexadecimal
For NYSCPT
Summer Institute,
NYU 8-16-02
Andrew O’Neill
Columbia University
Introduction
●
●
Why do people and computers think in different
ways?
How do people think about numbers? Where did
these ideas come from?
●
How do computers use numbers?
●
How can we speak the computer's language?
●
Two mysteries solved - you too can count to 1000
on two hands!
History of (human) numbers
●
●
1st Mystery: The Mesopotamians used a base-60
number system, from which we still use minutes,
seconds and degrees.
Greeks/Romans use base-10, in a different form...
12 3 4 5 6
7
8
9
I II III IV V VI VII VIII IX
X, L, C, D, M
We have 10 fingers, so this makes sense, right?
●
Refined by introduction of zero and the place
system - 'decimal' as we know it
0123456789
10, 100, 1000...
–
Allows us to deal with very large numbers, and
fractions.
–
Proven successful over time.
How Computers Count
●
Computers are logical electronic devices
–
All data is just a combination of two states
'on' and 'off'.
●
●
These states are called “Binary digITs” (BITS),
which can only take a value of 1 or 0.
Use the place system just like decimal
1 represents decimal 'one', 10 represents decimal 'two'...
Binary - Decimal Comparison
BINARY
32s 16s 8s 4s 2s
1
1
0
1
1
1
1
0
1
0
1s
1
1
0
1
1
DECIMAL
100s 10s 1s
1
3
4
1
5
2
1
●
Maximum different values we can represent with
n bits is 2n.
●
One BYTE = 8 BITS
●
One BYTE holds 2n = 256 different values.
●
●
ASCII is a code for most characters between 0 &
255
Oh yeah, computers typically start counting at
zero!
ASCII Codes in Decimal
000
001
008
009
016
017
024
025
032
033
040 (
041
048 0
049
056 8
057
064 @
065
072 H
073
080 P
081
088 X
089
096 `
097
104 h
105
112 p
113
120 x
121
...128 to
002
010
018
026
!
034
)
042
1
050
9
058
A
066
I
074
Q
082
Y
090
a
098
i
106
q
114
y
122
255 used
003
011
019
027
"
035 #
*
043 +
2
051 3
:
059 ;
B
067 C
J
075 K
R
083 S
Z
091 [
b
099 c
j
107 k
r
115 s
z
123 {
for non-latin
004
005
012
013
020
021
028
029
036 $
037
044 ,
045
052 4
053
060 <
061
068 D
069
076 L
077
084 T
085
092 \
093
100 d
101
108 l
109
116 t
117
124 |
125
characters...
%
5
=
E
M
U
]
e
m
u
}
006
014
022
030
038
046
054
062
070
078
086
094
102
110
118
126
&
.
6
>
F
N
V
^
f
n
v
~
007
015
023
031
039
047
055
063
071
079
087
095
103
111
119
127
'
/
7
?
G
O
W
_
g
o
w
Hexadecimal
●
Base 16
●
Need more symbols than 0,1,...,9
●
1 2 3 4 5 6 7 8 9AB C D E
●
"Ox" notation
Ox15 = 16 in decimal (1*16 + 5 = 21)
Bin - Hex – Dec Comparison
BINARY
16s 8s 4s 2s 1s
1
1 1
1 0 0
1
1 1 1
1 0
1 0 1
DECIMAL
100s 10s 1s
1
3
4
1 5
2 1
HEXADECIMAL
256s 16s 1s
1
3
4
E
1
5
So Why Hex?
●
Base 16, or 24
–
Holds as much information as 4 bits
–
E.g. 0xE is equivalent to binary 1111
●
1 byte can be represented by 2 hex characters
●
Saves writing 8 bits!
–
●
Saves space on small screens
Useful in displaying computer information
Communicating With Our Electronics
●
●
Our electronics board has 4 inputs
We need to tell it which ones to look for
coincidences on
Input 4 Input 3 Input 2 Input 1
on
off
on
on
off
off
on
on
Bin Code Hex Code
1011
0xB
0011
0x3
Calculator Demo
Counting to 1000
So why base 60?
●
Mesopotamians had cool numbers…
Theory #1
60 is the smallest number divisible by 2, 3, 4, and
5.
●
Theory #2
●
Mixing of two civilizations, one with base 5, one
with base 12…
Theory #3
Three-parts to each finger on right hand = 12
●
Point to one of these 12 parts with one of 5
fingers on left hand
●
5x12 = 60
●
… Theory # …
●
Astronomical, geometrical, yada yada
The Real Reason
●
There are 0x3C reasons why the ancient
civilizations used base-60!!!