There are 10 kinds of people in the world: those that
understand binary and those that do not...
Readings: Petzold, CHAPTER 1 /
Emu: Number Systems
.. How are things represented inside a computer?
- What is a byte? bit? megabyte?
- What is a positional numbering system? Ever use one?
- What is binary and ... WHY did they do this to us??
- The following table shows how you can express the same abstract
concept, a number, in base 2 and in base 10. (See reference)
| BINARY (base 2) |
DECIMAL (base 10) |
| 0 | 0 |
| 1 | 1 |
| 10 (2^1) | 2 |
| 11 | 3 |
| 100 (2^2) | 4 |
| 101 | 5 |
| 110 | 6 |
| 111 | 7 |
| 1000 (2^3) | 8 |
| 1001 | 9 |
| 1010 | 10 (10^1) |
| 1011 | 11 |
| 1100 | 12 |
| 1101 | 13 |
| 1110 | 14 |
| 1111 | 15 |
| 10000 (2^4) | 16 |
| . . . | . . . |
| 11111 | 31 |
| 100000 (2^5) | 32 |
| . . . | . . . |
| 111111 | 63 |
| 1000000 (2^6) | 64 |
| BINARY |
DECIMAL |
NOTE:
Powers of 2 are: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, (x2)...
Powers of 10 are: 10, 100, 1000, 10000, (x10)...
- Unsigned binary: Number 3 is encoded as ?
- Signed binary: Encodes negative numbers
- Floating Point: sign, power, mantissa
- ASCII (See reference)

- "A" is encoded as 1000001 (66th character)
- The character "3" is encoded as 0011 0011
- Unicode (65536 characters) - 2 bytes per char
- Instruction Codes
- The BIG QUESTION: What is the ONLY language a computer understands?
- The BIGGER QUESTION: How do we tell what ANYTHING is?? It's all just 1's and 0's!
What is THIS? Shorthand?
- 4 binary digits = ??
0000 : 0 1000 : 8
0001 : 1 1001 : 9
0010 : 2 1010 : A
0011 : 3 1011 : B
0100 : 4 1100 : C
0101 : 5 1101 : D
0110 : 6 1110 : E
0111 : 7 1111 : F
The following table shows how you can express the same abstract concept, a number, in three
different bases: base 2, base 10 and base 16 (a shorthand for base 2 numbers).
| BINARY (base 2) |
HEX (base 16) |
DECIMAL (base 10) |
| 0 | 0 | 0 |
| 1 | 1 | 1 |
| 10 (2^1) | 2 | 2 |
| 11 | 3 | 3 |
| 100 (2^2) | 4 | 4 |
| 101 | 5 | 5 |
| 110 | 6 | 6 |
| 111 | 7 | 7 |
| 1000 (2^3) | 8 | 8 |
| 1001 | 9 | 9 |
| 1010 | A | 10 (10^1) |
| 1011 | B | 11 |
| 1100 | C | 12 |
| 1101 | D | 13 |
| 1110 | E | 14 |
| 1111 | F | 15 |
| 10000 (2^4) | 10 (16^1) | 16 |
| . . . | . . . | . . . |
| 11111 | 1F | 31 |
| 100000 (2^5) | 20 | 32 |
| . . . | . . . | . . . |
| 111111 | 3F | 63 |
| 1000000 (2^6) | 40 | 64 |
| BINARY | HEX | DECIMAL |
NOTE:
Powers of 2 are: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, ...
Powers of 16 are: 16, 256, 4096, 65536, ...
Powers of 10 are: 10, 100, 1000, 10000, ...
There are lots of other "numbers" used in the field of computer science
What do we call these small numbers? What are they?
(.001 = 1 ms) 10-3
(.000 001 = 1 us)10-6
(.000 000 001 = 1 ns)10-9
(.000 000 000 001 = 1 ps)10-12
What do we call these large #s? (See reference)
(210 = KB, 220 = MB, 230 = GB)
| Name |
Abbr. |
Size |
| Kilo |
K |
2^10 = 1,024 |
| Mega |
M |
2^20 = 1,048,576 |
| Giga |
G |
2^30 = 1,073,741,824 |
| Tera |
T |
2^40 = 1,099,511,627,776 |
| Peta |
P |
2^50 = 1,125,899,906,842,624 |
| Exa |
E |
2^60 = 1,152,921,504,606,846,976 |
| Zetta |
Z |
2^70 = 1,180,591,620,717,411,303,424 |
| Yotta |
Y |
2^80 = 1,208,925,819,614,629,174,706,176 |
From www.howstuffworks.com
If we can represent numbers in binary, can we add? (sub multiply divide)
How?
Math is an important part of Computer Science!!
.. How do we convert between the three bases (10, 2, 16)?
- Binary to decimal? Add place values... (32, 16, 8, 4, 2, 1)
Binary to hex? Group....
Hex to binary? Ungroup...
Hex to decimal? Add place values... (4096, 256, 16, 1)
Decimal to Binary? intuition OR divide by 2 and concatenate remainder digits
Decimal to Hex? intuition OR divide by 16 and concatenate remainder digits.
.. How do we represent negative numbers?
Sign Magnitude One's Complement Two's Complement
000 = +0 000 = +0 000 = +0
001 = +1 001 = +1 001 = +1
010 = +2 010 = +2 010 = +2
011 = +3 011 = +3 011 = +3
100 = -0 100 = -3 100 = -4
101 = -1 101 = -2 101 = -3
110 = -2 110 = -1 110 = -2
111 = -3 111 = -0 111 = -1
Issues: balance, number of zeros, ease of operations
Which one is best? Why?
What is the scheme?
What's the range?
What is meant by "taking the "twos complement"?
What is meant by a "twos complement" number? (DIFFERENT!!)
Why does
0000 1010b = 10?
1111 0110b = NEG(10) = -10
Place values change in 2's comp
128 64 32 16 8 4 2 1 = unsigned
-128 64 32 16 8 4 2 1 = 2's complement
Better than sign mag or 1's comp
Experiment with 4 bit scheme
=================================================================
32 bit signed numbers (2s complement):
0000 0000 0000 0000 0000 0000 0000 0000 = 0
0000 0000 0000 0000 0000 0000 0000 0001 = + 1
0000 0000 0000 0000 0000 0000 0000 0010 = + 2
...
0111 1111 1111 1111 1111 1111 1111 1110 = + 2,147,483,646
0111 1111 1111 1111 1111 1111 1111 1111 = + 2,147,483,647
1000 0000 0000 0000 0000 0000 0000 0000 = – 2,147,483,648
1000 0000 0000 0000 0000 0000 0000 0001 = – 2,147,483,647
1000 0000 0000 0000 0000 0000 0000 0010 = – 2,147,483,646
...
1111 1111 1111 1111 1111 1111 1111 1101 = – 3
1111 1111 1111 1111 1111 1111 1111 1110 = – 2
1111 1111 1111 1111 1111 1111 1111 1111 = – 1
.. Floating Point??
2^3 2^2 2^1 2^0 2^-1 2^-2 2^-3 2^-4 2^-5 2-6
8 4 2 1 . 1/2 1/4 1/8 1/16 1/32 1/64
.5 .25 .125 .0625 .03125 .015625
11.011 = 3.375
101.101 = 5.625
-.001 = -.125
11.011 = 3.375 = 1.1011 x 21
101.101 = 5.625 = 1.01101 x 22
-.001 = -.125 = -1.0 x 2-3
IEEE 754 summary: (1)sign ´ (23) 1 + fraction ´ (8) exponent – bias 127
==========================================================================
IEEE 754: (1 bit) Sign is 1 for negative, 0 for positive
left-most bit
IEEE 754: (8 bits) Exponent is 'biased' to make sorting easier
bias of 127 for single precision (add 127 encoding, subtract 127 decoding)
all 0s is smallest exponent (0-127 = -127)
all 1s is largest (255-127 = 128)
so an exponent of 3 is encoded as 130 = 10000010 (3 + 127)
IEEE 754: (23 bits) Fraction is normalized to have a leading one
(which is then implied to save a bit!)
3.5 = 011.10
= 001.11 x 21 (1.75 x 2)
so fraction encoded as 1100000... (leading 1 is implied)
9.0 = 1001.0
= 0001.001 x 23 (1.125 x 8)
so fraction encoded as 0010000... (leading 1 is implied)
Example:
decimal: -.75 = -3/4 = -( ½ + ¼)
binary: -.11 = -1.1 x 2-1
fraction => .1000000000... encoded (leading 1 of 1.1 implied)
exponent => -1+127 = 126 = 01111110
sign => 1 ( 1 means negative )
IEEE single precision:
1 01111110 10000000000000000000000
to represent in hex, simply group into groups of 4 bits:
1011 1111 0100 0000 0000 0000 0000 0000
b f 4 0 0 0 0 0 = hex
.. ASCII: Characters and Strings
A 1-byte ASCII code is stored for each printable character
'a', 'B', '=', '1', '0', etc...
A string is stored as an array of characters
===================================================
We can store 123
as an integer OR as the string "123" or as the integers 1, 2 and 3
0106: 7B y db 123 // int 123
0100: 31 32 33 x db "123" // string "123"
0103: 01 02 03 z db 1,2,3 // 3 ints: 1, 2 & 3
Which when?? BIG DIFF!
Must convert!!
.. Instructions / OP Codes
Instruction MOV AL, 255
has the equivalent binary code: B0 FF (1011 0000 1111 1111)
Instruction MOV BX, 500
becomes => BB F4 01
looking at an emu program segment
[ 7] 0100: BB F4 01 mov bx, 500
[ 8] 0103: 05 03 00 add ax, 3
[ 9] 0106: 8A 2E 0B 01 mov ch, x
[ 10] :
[ 11] 010A: C3 ret
[ 12] :
[ 13] 010B: 63 x db 99
OP CODES (emu)
HEX OP CODE LIST
PROPOSED ADDITIONS TO THE IBM INSTRUCTION SET IBM Intrepid Use Only
IBM Model 3090/69 Features & Assembler Language Commands
*** J O K E *****
AAAH Add And Automatically Halt
AARTZ Add And Reset To Zero
ACM Automatically Clear Memory
BAH Branch And Hang
BBC Branch Before Compare
BBW Branch Both Ways
BEW Branch Either Way
BH Branch and Hang
BLMNF BLow MaiN Fuse
BNEV Branch NEVer
BOC Branch OCcasionally
BOPO Branch On Power Off
BOSO Branch On Sleepy Operator
BOV Burn Out Vdu
BOXMS Branch On Index Missing
BPDI Be Polite, Don't Interrupt
BPE Bypass Program Error
BPECK ByPass Error ChecK
BPO Branch on Power Off
BRST BRanch SomeTimes
CDHI Crash Disk Head Immediate
CEMU Close Eyes and Monkey with User space
CIRM Circulate Memory
CLBR CLobber ReGister
CLBRI CLobber ReGister Immediately
CM Circulate Memory
CMBG Create Machine Bug
CNFM Confuse Memory
CNFOP Confuse Operator
CPPR Crumple Printer Paper and Rip
CRB CRash and Burn
CRDT CReate Data
CTRNS Convert To Roman Numerals
CU Convert to Unary
CVUME Cover Up Machine Errors
DAC Divide And Conquer
DAMIT Transfer Control to Perdition
DAO Divide And Overflow
DC divide and conquer
DMC Destroy Memory Chip
DMNS Do what I Mean, Not what I Say
DNPG Do Not Pass Go
DO Divide and Overflow
DSTME Destroy Memory
ECL Early Card Lace
EDPMAB Electrocute DP Manager And Branch
EIOC Execute Invalid OpCode
EJD Eject Disk
EPE Execute Program Error
EPI Execute Programmer Immediately
EPMAS Erase Protected Memory Areas
ERCDP Erase Card Punch
ERCDS Erase Cards
EROS Erase Read-Only Storage
ERPTW Erase Print Wheel
ERROS Erase Read Only Storage
ESTOP Emergency STOP ** RESIST ALL EFFORTS TO RESTART **
ETCRD Eat Card
EXIOC Execute Invalid Op Code
EXOP Execute Operator
EXPP EXecute Political Prisoner
HCF Halt and Catch Fire ** PRIVILEGED OPERATION **
HCFC Branch Before Compare
HCFR Halt and Catch FiRe ** PRIVILEGED OPERATION **
HDLF Hurl Disc Like Frisbee
IAI Inquire And Ignore
IBP Insert Bug and Proceed
JRA Jump to Random Address
JSRLR Jump to SubRoutine and Lose return Address
LCC Load and Clear Core
LGOWY Load and Go Away
LMBR Lose Message and Branch
LPCON Loop Continuous
LUPGA Loop Until Programmer Goes Away (in desperation)
MBF Multiply and Be Fruitful
MDRBT Move and Drop Bits
MKTIV Make Tape Invalid
MVWRC Move and Wrap Core
NBC Negate By Clearing
OOOH Or Only On Half-hours
PBC Print and Break Chain
POF Print On Fly
POPI Punch OPerator Immediately
PRANB Pick up Random Bits
PRSMR Print and Smear
PS* Punch obscenity
PSD Pause and Smoke Dope
PSP Print and Shred Paper
PVLC Punch Variable Length Card
RBAFG Read Binary And Forget
RPM Read Programmer's Mind
RPTR Read from Printer
RSC Read and Shred Card
RSPP Randomly Shred Printer Paper
SLD Slip Disk
SOT Sit On a Tack
SPRDK Shuffle Program Deck
SPSW Scramble Program Status Word
SPT Scramble Protected Tapes
SQPC Sit Quietly and Play with your Crayons
TCTDK Transfer Control To Disk
TCTOL Transfer Control To Overhead Lights
TCTPL Transfer Control To Pilot Lights
TCTWS Transfer Control To Wall Socket
WPM Write Programmer's Mind
WRR Write Random Record
WWRLR Write Wrong Length Record
XMAS eXclusive OR Main Areas of Storage
XSP eXecute Systems Programmer
ZIPEX Address by Nine-Digit Zipcode
.. How do we interpret all these 1's and 0's?
Even if we know that a block of memory contains data, to obtain its value we
need to choose an interpretation - Have to 'know the code'...
Examples: What does '0100 0001' represent?
a number?
which one?
signed int? unsigned int? part of a floating point?
and how do we write it?
hex 41 or decimal 65 or binary 1000001? or octal 101?
is it the ASCII code for what character?
or is it some instruction?
If we know that 0100 0001 is an ascii character, which one?
down across
addsub.obj -- object file created by the assembler
00000000 4C 01 06 00 8B F4 7D 3D-D0 0B 00 00 1C 00 00 00 L.....}=........
00000010 00 00 00 00 2E 74 65 78-74 00 00 00 00 00 00 00 .....text.......
00000020 00 00 00 00 22 00 00 00-04 01 00 00 26 01 00 00 ....".......&...
00000030 62 01 00 00 06 00 07 00-20 00 30 60 2E 64 61 74 b....... .0`.dat
00000040 61 00 00 00 22 00 00 00-00 00 00 00 10 00 00 00 a..."...........
00000050 8C 01 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00000060 40 00 30 C0 53 54 41 43-4B 00 00 00 32 00 00 00 @.0.STACK...2...
00000070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00000080 00 00 00 00 00 00 00 00-40 00 30 C0 2E 64 65 62 ........@.0..deb
00000090 75 67 24 53 32 00 00 00-00 00 00 00 51 01 00 00 ug$S2.......Q...
000000A0 9C 01 00 00 EE 02 00 00-00 00 00 00 0A 00 00 00 ................
000000B0 40 00 10 42 2E 64 65 62-75 67 24 54 83 01 00 00 @..B.debug$T....
000000C0 00 00 00 00 70 08 00 00-52 03 00 00 00 00 00 00 ....p...R.......
000000D0 00 00 00 00 00 00 00 00-40 00 10 42 2E 64 72 65 ........@..B.dre
000000E0 63 74 76 65 F3 09 00 00-00 00 00 00 0E 00 00 00 ctve............
000000F0 C2 0B 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00000100 00 0A 00 00 A1 00 00 00-00 03 05 00 00 00 00 2B ...............+
00000110 05 00 00 00 00 A3 00 00-00 00 E8 00 00 00 00 6A ...............j
00000120 00 E8 00 00 00 00 01 00-00 00 0F 00 00 00 06 00 ................
00000130 07 00 00 00 10 00 00 00-06 00 0D 00 00 00 12 00 ................
SO, HOW DOES a COMPUTER KNOW WHAT a BYTE of ONES and ZEROES MEANS??!
.. Martian Fingers?
A person lands on Mars and looks in a building that she finds.
It appears to be a school. The teacher has the following on the board:
6 + 4 = 12 10 x 10 = 100 13 + 6 = 21
So, how many fingers do Martians have?
.. Binary Barbeque?
We have 12 (base ____) hotdogs that will match perfectly with our
package of 18 (base 10) buns.
We have a baker's dozen hamburger rolls and 10 (base ____) patties
which will match up perfectly.
We invited _____ people (base 7) meaning everyone will have one (base 3)
sandwich of some sort.
It was supposed to last 11 hours (base ____) which is like
going to 4 MWF classes!
This is the last of these 101 (base ____) statements about my BB.
quiz1a.txt quiz1b.txt a0ans.txt