Lecture 1
Lecture 1
• Discussion section
– J11-406, Friday. 16:00-17:40
understanding computers
• Understanding programming requires that you understand computers
• How does a computer work?
– Idiot savant
– very accurately
– represents a power of 2
human numbers
• You are familiar with decimal (base 10)
dn dn-1 dn-2 … d2 d1 d0
dn10n + dn-1 10n-1 + dn-2 10n-2… d2 102 + d1 101 + d0 100
38649
3104 + 8 103 + 6 102 + 4 101 + 9 100
binary
bn bn-1 bn-2 … b2 b1 b0
bn2n + bn-1 2n-1 + bn-2 2n-2… b2 22 + b1 21 + b0 20
• Example:
10110110
127 + 0 26 + 1 25 + 1 24 + 0 23 + 1 22 + 1 21 + 0 20
1128 + 0 64 + 1 32 + 1 16 + 0 8 + 1 4 + 1 2 + 0 1
128 + 32 + 16 + 4 + 2
182
teminology
• bit: binary digit
• byte: a group of 8 bits
• nybble (obsolete): half a byte
• word: a group of bytes that a specific computer is optimized for working with (usually
4 or 8)
• kilobyte (K or KB): 1,000 bytes, or sometimes 1,024 bytes (210)
• megabyte (M or MB): 1,000,000 bytes, or sometimes 1,048,576 bytes (220), 1,024K
bytes
why all these powers of 2?
• Everything is little electronic switches
– off or on
– true or false
– yin or yang(阴或阳)
– 0 or 1
on on-1 on-2 … o2 o1 o0
on8n + on-1 8n-1 + on-2 8n-2… o2 82 + o1 81 + o0 80
3264
3 83 + 2 82 + 6 81 + 4 80
3 512 + 2 64 + 6 8 + 4
1536 + 128 + 48 + 4 = 1716
other numbering systems
• hexadecimal – base 16
– used occasionally – you can’t really avoid it
8b7e
8 163 + 11 162 + 7 161 + 14 160
8 4096 + 11 256 + 7 16 + 14
32768 + 2816 + 112 + 14 = 35710
other numbering systems
• You do not have to be fluent in either of these (octal or hex) for this class
– recognize them
– -128 to 127
word
• Also fundamental to the computer
• A group of bytes
– usually 4 or 8
• 4 bytes
– 32 bits
– 0 to 4,294,967,295
– into words
– called an address
– real numbers
– text
• This is important!
• Instructions are numbers
• Random numbers can be executed
– but will not be a program
00401040 55 8B EC 83 EC 5C 53 56 57 6A 00 FF 15 B8 C2 42
00401050 00 89 45 FC 83 7D FC 00 7D 1B 68 0F 10 40 00 68
00401060 14 61 42 00 B9 E8 99 42 00 E8 32 05 00 00 8B C8
00401070 E8 90 FF FF FF 8D 45 EC 50 8B 0D 50 8D 42 00 51
00401080 FF 15 C0 C2 42 00 89 45 FC 83 7D FC 00 7D 20 68
00401090 0F 10 40 00 68 F8 60 42 00 B9 E8 99 42 00 E8 FD
004010A0 04 00 00 8B C8 E8 5B FF FF FF E9 9C 00 00 00 68
004010B0 0F 10 40 00 68 D8 60 42 00 B9 E8 99 42 00 E8 DD
004010C0 04 00 00 8B C8 E8 3B FF FF FF 8D 55 E4 52 68 28
004010D0 71 42 00 6A 01 6A 00 68 18 71 42 00 FF 15 C4 C2
004010E0 42 00 89 45 FC 83 7D FC 00 7C 1D 68 0F 10 40 00
004010F0 68 B4 60 42 00 B9 E8 99 42 00 E8 A1 04 00 00 8B
00401100 C8 E8 FF FE FF FF EB 43 8B 45 FC 50 68 88 60 42
00401110 00 E8 6A 25 00 00 83 C4 08 68 0F 10 40 00 68 84
00401120 60 42 00 8B 4D FC 51 68 60 60 42 00 B9 E8 99 42
00401130 00 E8 6A 04 00 00 8B C8 E8 33 01 00 00 8B C8 E8
00401140 5C 04 00 00 8B C8 E8 BA FE FF FF FF 15 BC C2 42
• Compiled languages
– converted into machine language before use
• Interpreted languages
– converted into machine language during use
• Computer domain
– programmer is willing to think about the computer
tradeoffs
• Control
• Ease-of-programming
• Performance
• Flexibility
different approaches
• Procedural
• Object-oriented
special features
• There are lots of special-purpose languages
– video games
– robots
– artifical intelligence
– embedded systems
– etc.