Title: Computer Systems
1Computer Systems
- Data Representation andComputer Arithmetic
2Data Representation
- Binary codes used to represent numbers
- Conversion between number systems
- Binary ?? decimal
- Hexadecimal ?? decimal
- Between arbitrary number systems
- Representation of positive/negative numbers
- Floating point representation
3Bit, Byte and Word
- Bit is the smallest quantity that can be handled
by computer 1 or 0. - Byte is a group of 8 bits.
- Word is the basic unit of data that can be
operated by computer e.g., 16 bits.
- Some architectures have 8, 32, or 64-bit words
4- Content of Word
- Bit Pattern
- May represent many things
- Actual meaning of a particular bit pattern is
given by the programmer - Computer itself cannot determine the meaning of
the word - Classic question Can you tell the meaning of a
word picked randomly from the memory?
5- Instruction (op-code)
- A single word defines an action that is to be
performed by CPU
- Numeric Quantity
- Character
- A to Z, a to z, 0 to 9, , -, , etc.
- ASCII Code
- - Representation of a character by 7 bits.
- - The ASCII for W is 101 01112, or 5716
6ASCII Code
7Pixel (Picture Element)
- The smallest unit to construct a picture
- 1bit/pixel for black-and-white pictures, gt1
bits/pixel for gray scale or color pictures, e.g.
24bits/pixel. - A letter is represented by a group of pixels on
computer screen.
8Positional Notation
- Weight is associated with the location within a
number. - The 9 in 95 has weight 10
- A number N in base b is represented by
9Example
10Number Bases
- Decimal (b10) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
- Octal (b8) 0, 1, 2, 3, 4, 5, 6, 7
- Hexadecimal (b16)
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
11How many binary bits are needed to represent an
n-digits decimal?
- The value of an m-bit binary is up to
- The value of an n-digit decimal is up to
- so
-
OR
12How many bits are needed to represent an n-digits
octal?How many bits are needed to represent
an n-digits hexadecimal?
Questions
13Conversion of Integer - Decimal to Binary
- Divide a decimal successively by 2, record the
remainder, until the result of the division is 0.
67/2 33 Rem.1 33/2 16 Rem.1 16/2
8 Rem.0 8/2 4 Rem.0
4/2 2 Rem.0 2/2 1 Rem.0 1/2 0 Rem.1
14Conversion of Integer - Decimal to Hexadecimal
- Divide a decimal successively by 16, record the
remainder, until the result is 0
432/16 27 Rem.0 27/16 1 Rem.B 1/16
0 Rem.1
15Conversion of integer - Binary to Decimal
Conversion of integer - Hexadecimal to Decimal
16Conversion of integer - Hexadecimal Binary
Conversion of integer - Octal Binary
17Conversion of Fraction - Decimal to Binary
- The fraction is repeatedly multiplied by 2, the
integer part is stripped and recorded.
0.687510 2 1.375 1 0.37510 2
0.75 0 0.7510 2 1.5 1 0.510 2
1.0 1 0.010 2 0.0 end
18Conversion of Fraction - Binary Hexadecimal
0.1010110012 0.1010 1100 10002
0.AC816 0.7BC16 0.0111 1011 11002
0.01111011112
19Binary Coded Decimal (BCD)
- A decimal digit is coded into 4 bits ? 1 byte
can store 2 digits - Example
- 1942 is encoded as
- 0001 1001 0100 0010 (2 bytes)
- Disadvantages
- Complex arithmetic
- Inefficient use of storage
- Advantage
- Can represent real number
Decimal BCD 0 0000 1 0001 2
0010 3 0011 4 0100 5 0101 6
0110 7 0111 8 1000 9 1001
20Binary Addition
0 0 1 1 0 1 1 1 0 1 0 1 0 1 1 0
1 1 1 1 1 Carry 1 0 0 0
1 1 0 1
Binary Subtraction ?
- use 2s complementary arithmetic (later )
21 Signed Integer Representations
- Sign-and-Magnitude
- 1s Complement
- 2s Complement
22Sign-and-Magnitude Representation
- Use the most significant bit (MSB) to indicate
the sign of the number. - The MSB is 0 for positive, 1 for negative.
- 8 bits represent -12710 to 12710
- Examples 00101100 for 4410
- 10101100 for -4410
231s Complement
- Just flip the bits!
- The MSB is 0 for positive, 1 for negative.
- 8 bits represent -12710 to 12710
- Examples 00101100 for 4410
- 11010011 for -4410
242s Complement
- The 2s complement for N is
- Example Using 5 bits (n 5), if N 7, then
0 1 1 0 0 1 1 0 0 1 1) 0 0 1 0 1
12 -7 5
- 2s complement 1s complement 1
7 0 0 1 1 1 1s complement 1 1 0 0 0
1 2s complement 1 1 0 0 1 -7
252s Complement (con.)
- To form the twos complement of a number, simply
invert the bits (1 to0, 0 to 1), and add 1 ? 1s
complement 1 - 1310 0 0 0 0 1 1 0 1
- -1310 1 1 1 1 0 0 1 0 1
- 1 1 1 1 0 0 1 1
26Properties of 2s Complement
- One unique 0
- MSB 0, positive number
- MSB 1, negative number
- The range is
- For 5 bits, the range is -1610 (10000) to 1510
(01111) - The 2s complement of the complement of X is X
itself (Prove )
272s Complementary Arithmetic
- Subtraction is performed using addition
- A - B A (-B)
- X 910 010012, Y 610 001102
- -X -910 101112, -Y -610 110102
28Binary Adder/Subtractor
29Arithmetic Overflow
- The overflow happens when
- positive positive ? negative
- negative negative ? positive
- If are MSBs, then the overflow bit v is
expressed as
30Arithmetic Overflow
- Case I A and B are
- an-1 __ bn-1 __
- cn __ cn-1 __
- V _____
- Case II A and B are
- an-1 __ bn-1 __
- cn __ cn-1 __
- V _____
Most significant stage of full adder
31Fixed-point Arithmetic
3.62510 ? 0011.10102 ? 00111010 6.510 ?
0110.10002 ? 01101000 10.12510
10100010 The fraction point is added 10100010
-gt 1010.00102
32Floating Point Numbers
- Scientific Notation
- a is mantissa, r is radix, e is exponent
33IEEE Floating Point Format
S Sign bit, 1 bit E Exponent, 8 bits B Bias, 8
bits, 127100111 1111 F mantissa
34IEEE Floating Point - Example
- Normalization, e.g.,
- Use sign and magnitude representation for signed
mantissa. - Use biased exponent, e.g. in excess 127
35IEEE Floating Point - Example
-2345.125 -100100101001.0012 1)
Normalization 2) Negative mantissa, so S 1 3)
Exponent E 11 127 13810 100010102 4)
Mantissa F 00100101001 0010000 1 10001010
001001010010010000
36IEEE Floating Point Format Special Cases
- Zero exponent and fraction all 0s
- Denormalized exponent all 0s,
- fraction non-zero
- for single precision
- Infinity exponents all 1s, fraction all 0s
- sign bit determines infinity or -infinity
- Not a Number (NaN) exponents all 1s,
- fraction non-zero
- A good reference is available at
- http//research.microsoft.com/hollasch/cgindex/
coding/ieeefloat.html
37Bit Patterns and Logical Operations
They are bit-wise operations.
38AND Operation
- x AND y is true, if and only if both bits x and
y are true. - A 1 1 0 0 1 0 1 1
- B 0 1 1 0 1 1 0 1
- CA AND B 0 1 0 0 1 0 0 1
OR Operation
- x OR y is true, if either bits x or y is true.
- A 1 1 0 0 1 0 1 1
- B 0 1 1 0 1 1 0 1
- CA OR B 1 1 1 0 1 1 1 1
39NOT Operation
- A 1 becomes 0, and a 0 becomes 1.
- A 1 1 0 0 1 0 1 1
- C NOT A 0 0 1 1 0 1 0 0
EOR (Exclusive OR) Operation
- It is true, if and only if just one of inputs is
true. - A 1 1 0 0 1 0 1 1
- B 0 1 1 0 1 1 0 1
- C A EOR B 1 0 1 0 0 1 1 0