How Computers Think: Binary, Decimal and Hexadecimal For NYSCPT Summer Institute, NYU 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 ● 1 st 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 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 , 100, – 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
● Maximum different values we can represent with n bits is 2 n. ● One BYTE = 8 BITS ● One BYTE holds 2 n = 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 !034 "035 #036 $037 %038 &039 ' 040 (041 )042 * , / :059 ; ? A066 B067 C068 D069 E070 F071 G 072 H073 I074 J075 K076 L077 M078 N079 O 080 P081 Q082 R083 S084 T085 U086 V087 W 088 X089 Y090 Z091 [092 \093 ]094 ^095 _ 096 `097 a098 b099 c100 d101 e102 f103 g 104 h105 i106 j107 k108 l109 m110 n111 o 112 p113 q114 r115 s116 t117 u118 v119 w 120 x121 y122 z123 {124 |125 }126 ~ to 255 used for non-latin characters...
Hexadecimal ● Base 16 ● Need more symbols than 0,1,...,9 ● A B C D E ● "Ox" notation Ox15 = 16 in decimal (1* = 21)
Bin - Hex – Dec Comparison
So Why Hex? ● Base 16, or 2 4 – 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
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!!!