Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Representation and Computer Arithmetic

Similar presentations


Presentation on theme: "Data Representation and Computer Arithmetic"— Presentation transcript:

1 Data Representation and Computer Arithmetic
Computer Systems Data Representation and Computer Arithmetic

2 Data 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

3 Bit, 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. Bit Byte Word 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 , or 5716

6 ASCII Code

7 Pixel (Picture Element)
The smallest unit to construct a picture 1bit/pixel for black-and-white pictures, >1 bits/pixel for gray scale or color pictures, e.g. 24bits/pixel. A letter is represented by a group of pixels on computer screen. Pixel (1)

8 Positional 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

9 Example:

10 Number Bases Decimal (b=10): {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Binary (b=2): {0, 1} Octal (b=8): {0, 1, 2, 3, 4, 5, 6, 7} Hexadecimal (b=16): {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}

11 How 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

12 Questions How many bits are needed to represent an n-digits octal? How many bits are needed to represent an n-digits hexadecimal?

13 Conversion 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

14 Conversion 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/ = 0 Rem.=1

15 Conversion of integer - Binary to Decimal
Conversion of integer - Hexadecimal to Decimal

16 Conversion of integer - Hexadecimal Binary
5 7 1011 B 0010 0111 Conversion of integer: - Octal Binary 2 7 1 010 111 101

17 Conversion of Fraction - Decimal to Binary
The fraction is repeatedly multiplied by 2, the integer part is stripped and recorded. = Question: Convert 0.625? 0.110? * 2 = * 2 = * 2 = 0.510 * 2 = 0.010 * 2 = end

18 Conversion of Fraction - Binary Hexadecimal
= = 0.AC816 0.7BC16 = = Convert Convert 0.6D5?

19 Binary Coded Decimal (BCD)
A decimal digit is coded into 4 bits  1 byte can store 2 digits Example: 1942 is encoded as (2 bytes) Disadvantages Complex arithmetic Inefficient use of storage Advantage: Can represent “real” number Decimal BCD

20 Binary Addition Binary Subtraction ? 0 0 1 1 0 1 1 1 + 0 1 0 1 0 1 1 0
Carry Binary Subtraction ? use 2’s complementary arithmetic (later … )

21 Signed Integer Representations
Sign-and-Magnitude 1’s Complement 2’s Complement

22 Sign-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 to 12710 Examples: for +4410 for -4410 Problem: = +0, = -0

23 1’s Complement Just flip the bits!
The MSB is 0 for positive, 1 for negative. 8 bits represent to 12710 Examples: for +4410 for -4410 Problem: = +0, = -0

24 2’s Complement The 2’s complement for N is
Example: Using 5 bits (n = 5), if N = 7, then 12 -7 5 1) 2’s complement = 1’s complement + 1 1’s complement 2’s complement = -7

25 2’s Complement (con.) To form the two’s complement of a number, simply invert the bits (1 to0, 0 to 1), and add 1  1’s complement + 1 1310 = -1310 = = 2’s comp. -34?

26 Properties of 2’s Complement
One unique 0 MSB = 0, positive number MSB = 1, negative number The range is For 5 bits, the range is (10000) to (01111) The 2’s complement of the complement of X is X itself (Prove: )

27 2’s Complementary Arithmetic
Subtraction is performed using addition A - B = A + (-B) X = 910 = , Y = 610 = -X = -910 = , -Y = -610 = X -Y 310 1) - X - Y -1510 1)

28 Binary Adder/Subtractor

29 Arithmetic Overflow The overflow happens when
positive + positive  negative negative + negative  positive If are MSBs, then the overflow bit v is expressed as 12 +13 25 -12 -13 -25 1)

30 Arithmetic Overflow In practice, Case I: A and B are +
an-1 = __ bn-1 = __ cn = __ cn-1 = __ V = _____ Case II: A and B are – Most significant stage of full adder

31 Fixed-point Arithmetic
    The fraction point is added > What if we want to represent ? We need at least m > 3.3*n = 3.3*20 = 66 bits !

32 Floating Point Numbers
Scientific Notation a is mantissa, r is radix, e is exponent is for binary

33 IEEE Floating Point Format
S: Sign bit, 1 bit E: Exponent, 8 bits B: Bias, 8 bits, 12710= F: mantissa

34 IEEE Floating Point - Example
Normalization, e.g., Use sign and magnitude representation for signed mantissa. Use biased exponent, e.g. in excess 127 If we have 8 bits for exponent, to represent -5, we add ( ) to -5, the result is 12210=

35 IEEE Floating Point - Example
Represent in 32 bits ? = 1) Normalization: 2) Negative mantissa, so S = 1 3) Exponent: E = = = 4) Mantissa F = …000 …0 1.510 in IEEE format?

36 IEEE 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, A good reference is available at

37 Bit Patterns and Logical Operations
OR NOT Exclusive OR They are bit-wise operations.

38 AND Operation OR Operation
x AND y is true, if and only if both bits x and y are true. A = B = C=A AND B = OR Operation x OR y is true, if either bits x or y is true. A = B = C=A OR B =

39 EOR (Exclusive OR) Operation
NOT Operation A 1 becomes 0, and a 0 becomes 1. A = C = NOT A = EOR (Exclusive OR) Operation It is true, if and only if just one of inputs is true. A = B = C = A EOR B =


Download ppt "Data Representation and Computer Arithmetic"

Similar presentations


Ads by Google