n301/Encoding
n301.tplt
Chapter 4
The Hardware World
Binary number system
Base 2 instead of 10- 2 digits, 0 and 1
- BIT (Binary digIT)
Binary number system 2
All information stored internally in binary form- letters, intergers, decimal numbers, graphic images
- external/internal encoding/decoding
Internal representation
letters A = 01000001
integers 65 = 01000001
different information but same internal code
computer needs to know the data type to know how to interpret (assign meaning)
COMPUTER ARITHMETIC:Place Values
number system with five symbols: 0, 1, 2, 3, and 4
How would we count 7 coins?
1 stack & 2 coins
COMPUTER ARITHMETIC:Place Values 2
How would 24 coins look?
Or how about 25 coins?
COMPUTER ARITHMETIC:Place Values 3
numerical representaion scheme:- 4 = stack-of-stacks
- 1 = 1 stack of 5
- 3 = single coins
COMPUTER ARITHMETIC:Place Values 4
This idea of giving symbols different values that depends on where they are writen and using zeros to fill the empty positions is called the place-value system.
COMPUTER ARITHMETIC:Place Values 5
The stack size of number system is called its base
COMPUTER ARITHMETIC:Place Values 6
What number system (base) did we design?
COMPUTER ARITHMETIC:The Base-2 System - Binary
Binary Addition:
ZERO F 0
ONE T 1
TWO TF 10
THREE TT 11
FOUR TFF 100
FIVE ??? ???
COMPUTER ARITHMETIC:The Base-2 System - Binary 2
Binary Subtraction:
24 - 5 => ?? + 4 = 24
Ex: 10101 - 11 => ?????
+ 11
10101
COMPUTER ARITHMETIC:The Base-2 System - Binary 3
Multiplication:
100001
_x 101_
100001
000000
+ 100001
COMPUTER ARITHMETIC:Base10 => Base2 Conversion
Ex: 102410; 678610
COMPUTER ARITHMETIC:Base10 => Base2 Conversion 2
Negative Numbers in Binary
Three representation schemes are used:- Signed Magnitude
Left most bit is the sign bit (0 => + & 1 => -).
Remaining bits hold absolute magnitude.
COMPUTER ARITHMETIC:Base10 => Base2 Conversion 3
Ex: 210 => 0000 00102
-210 => 1000 00102
COMPUTER ARITHMETIC:Base10 => Base2 Conversion 4
- One's Compliment
Sign bit is similar to (1). The magnitude is complimented.
COMPUTER ARITHMETIC:Base10 => Base2 Conversion 5
Ex: 410 => 0000 01002
-410 => 1111 10112
COMPUTER ARITHMETIC:Base10 => Base2 Conversion 6
- Two's Compliment
Sign bit same as (1).
Magnitude is complimented first and a "1" is added to the complimented digits.
COMPUTER ARITHMETIC:Base10 => Base2 Conversion 7
Ex: 710 => 0000 01112
-710 => 1111 10012
COMPUTER ARITHMETIC:Base10 => Base2 Conversion 8
Ex: 7 + -3
COMPUTER ARITHMETIC: Octal Number System
Base=8
8 Symbols: {0,1,2,3,4,5,6,7}
COMPUTER ARITHMETIC: Octal Number System - Octal to Decimal
(an-1an-2 ... a1a0)8 = (an-1x8n-1+an-2x8n-2+ ... +a1x81+a0x80)10
Example:
(127)8 = (1x 82 + 2 x 81 + x 80) = (64 + 16 +)10 = (87)10
COMPUTER ARITHMETIC: Octal Number System - Decimal to Octal
Repeated division by 8.
(Similar to principle to generate binary codes).
Example: (213)10 = (what)8?1. 213/8 = 26(quotient),5(remainder) => lowest octal number = 5
2. 26/8 = 3(quitient), 2(remainder) => second octal digit = 2
3. 3/8 = 0(quotient), 3(remainder) => third octal digit = 3
Stop, since quotient = 0
Hence, (213)10 = (325)8
COMPUTER ARITHMETIC: Octal Number System - Octal to Binary
Expand each octal digit to 3 binary bits.
Example: (725)8 = (111|010|101)2
COMPUTER ARITHMETIC: Octal Number System - Binary to Octal
Combine every 3 bits into one octal digit.
Example: (110|010|011)2 = (623)8
COMPUTER ARITHMETIC: Hexadecimal Number System
Base = 16
16 symbols: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A(=10), B(=11), C(=12), D(=13), E(=14), F(=15)}
COMPUTER ARITHMETIC: Hexadecimal Number System - Hexdecimal to Decimal
(an-1an-2 ... a1a0)16 = (an-1x16n-1+an-2x16n-2+ ... +a1x161+a0x160)10
Example:
(1C7)16 = 1 162 + 12 x 161 + 7 x 160)10 = (256 + 197 + 7)10 = (455)10
COMPUTER ARITHMETIC: Hexadecimal Number System - Decimal to Hexdecimal
Repeated division by 16.
(similar in principle to generating binary and octal codes).
Example: (829)10 = (what)16?1. 829/16 = 51(quotient),13 = D(remainder) =>
lowest octal number = D
2. 51/16 = 3(quitient), 3(remainder) => second octal digit = 3
3. 3/16 = 0(quotient), 3(remainder) => third octal digit = 3
Stop, since quotient = 0
Hence, (829)10 = (33D)16
COMPUTER ARITHMETIC: Hexadecimal Number System - Hexadecimal to Binary
Expand each hexadecimal digit to 4 binary bits.
Eaxple: (E29)16 = (1110|0100|1001)2
COMPUTER ARITHMETIC: Hexadecimal Number System - Binary to Hexadecimal
Combine every 4 bits into one hexadecimal digit.
Eample: (0101|1111|1010|0110)2 = (5FA6)16