Title: How Computers Think: Binary, Decimal and Hexadecimal
1How Computers ThinkBinary, Decimal and
Hexadecimal
- For NYSCPT
- Summer Institute,
- NYU 8-16-02
- Andrew ONeill
- Columbia University
2Introduction
- 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!
3History 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...
- 1 2 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?
4- Refined by introduction of zero and the place
system - 'decimal' as we know it - 0 1 2 3 4 5 6 7 8 9 10, 100, 1000...
- Allows us to deal with very large numbers, and
fractions. - Proven successful over time.
5How 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'...
6Binary - Decimal Comparison
7- 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!
8ASCII Codes in Decimal
000 001 002 003 004 005 006 007
008 009 010 011 012 013 014 015
016 017 018 019 020 021 022 023
024 025 026 027 028 029 030 031
032 033 ! 034 " 035 036 037 038 039 '
040 ( 041 ) 042 043 044 , 045 - 046 . 047 /
048 0 049 1 050 2 051 3 052 4 053 5 054 6 055
7 056 8 057 9 058 059 060 lt 061 062
gt 063 ? 064 _at_ 065 A 066 B 067 C 068 D 069
E 070 F 071 G 072 H 073 I 074 J 075 K 076
L 077 M 078 N 079 O 080 P 081 Q 082 R 083
S 084 T 085 U 086 V 087 W 088 X 089 Y 090
Z 091 092 \ 093 094 095 _ 096 097
a 098 b 099 c 100 d 101 e 102 f 103 g 104
h 105 i 106 j 107 k 108 l 109 m 110 n 111 o
112 p 113 q 114 r 115 s 116 t 117 u 118 v 119 w
120 x 121 y 122 z 123 124 125 126 127
...128 to 255 used for non-latin
characters...
9Hexadecimal
- Base 16
- Need more symbols than 0,1,...,9
- 1 2 3 4 5 6 7 8 9 A B C D E F
- "Ox" notation
- Ox15 21 in decimal (116 5 21)
10Bin - Hex - Dec Comparison
ERRATA - should be 'F' on 4th row!!!
11So Why Hex?
- Base 16, or 24
- Holds as much information as 4 bits
- E.g. 0xF 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
12Communicating With Our Electronics
- Our electronics board has 4 inputs
- We need to tell it which ones to look for
coincidences on
13Calculator DemoCounting to 1000
14So why base 60?
- Mesopotamians had cool numbers
15Theory 1
- 60 is the smallest number divisible by 2, 3, 4,
and 5.
16Theory 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
17The Real Reason
- There are 0x3C reasons why the ancient
civilizations used base-60!!!