+ All Categories
Home > Documents > DATA REPRESENTATION

DATA REPRESENTATION

Date post: 30-Dec-2015
Category:
Upload: ulysses-blackwell
View: 21 times
Download: 0 times
Share this document with a friend
Description:
DATA REPRESENTATION. Computer organization TCS 303/TIT 304. I ntroduction A bit is the most basic unit of information in a computer. It is a state of “on” or “off” in a digital circuit. Or “high” or “low” voltage instead of “on” or “off.” A byte is a group of eight bits. - PowerPoint PPT Presentation
28
DATA REPRESENTATION Computer organization TCS 303/TIT 304
Transcript
Page 1: DATA REPRESENTATION

DATA REPRESENTATION

Computer organizationTCS 303/TIT 304

Page 2: DATA REPRESENTATION

Introduction

• A bit is the most basic unit of information in a computer.– It is a state of “on” or “off” in a digital circuit.– Or “high” or “low” voltage instead of “on” or “off.”

• A byte is a group of eight bits.– A byte is the smallest possible addressable unit of

computer storage.• A word is a contiguous group of bytes

– Word sizes of 16, 32, or 64 bits are most common.– Usually a word represents a number or instruction.

Page 3: DATA REPRESENTATION

Signed Fixed Point Numbers–For an 8-bit number, there are 28 = 256 possible bit

patterns. These bit patterns can represent negative numbers if we choose to assign bit patterns to numbers in this way. We can assign half of the bit patterns to negative numbers and half of the bit patterns to positive numbers.

–• Four signed representations we will cover are:

–Signed Magnitude

–One’s Complement

–Two’s Complement

–Excess (Biased)

Page 4: DATA REPRESENTATION

Signed Integer Representation

• Several representations exist for negative values:

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

Page 5: DATA REPRESENTATION

Sign Magnitude

– Leftmost bit is sign bit: 0 for positive, 1 for negative– Remaining bits are magnitude– Drawbacks:

• Sign bits give problems to addition and subtraction• Two representations for 0• Rarely used

– Also know as “sign and magnitude,” the leftmost bit is the sign (0 = positive, 1 = negative) and the remaining bits are the magnitude.

Page 6: DATA REPRESENTATION

Example:

+2510 = 000110012 -2510 = 100110012

• Two representations for zero:

+0 = 000000002,

-0 = 100000002.

• Largest number is +127, smallest number is -12710, using an 8-bit representation.

Page 7: DATA REPRESENTATION

Signed one’s Complement

– The leftmost bit is the sign (0 = positive, 1 = negative). Negative of a number is obtained by subtracting each bit from 2 (essentially, complementing each bit from 0 to 1 or from 1 to 0). This goes both ways: converting positive numbers to negative numbers, and converting negative numbers to positive numbers. Example:

– +2510 = 000110012 -2510 = 111001102

– • problem? Two representations for zero: +0 = 000000002, -0 = 111111112.

– • Largest number is +12710, smallest number is -12710, using an 8-bit representation.

Page 8: DATA REPRESENTATION

Signed two’s Complement

–The leftmost bit is the sign (0 = positive, 1 = negative). Negative of a number is obtained by adding 1 to the one’s complement negative. This goes both ways, converting between positive and negative numbers.

–Example (recall that -2510 in one’s complement is 111001102): +2510 = 000110012 -2510 = 111001112

–• One representation for zero: +0 = 000000002, -0 = 000000002.

Page 9: DATA REPRESENTATION

Addition and Subtraction in 2’s complement

•The rule for addition is add the two numbers, including their sign bits, and discard any carry out of the sign (leftmost) bit position. Numerical examples for addition are shown below.•Example:• + 6 00000110 - 6 11111010

+13 00001101 +13 00001101+19 00010011 +7 00000111

• +6 00000110 -6 11111010-13 11110011 -13 11110011 -7 11111001 -19 11101101

•In each of the four cases, the operation performed is always addition, including the sign bits.•Only one rule for addition, no separate treatment of subtraction. Negative numbers are always represented in 2’s complement.

Page 10: DATA REPRESENTATION

Overflow

•The detection of an overflow after the addition of two binary numbers depends on whether the considered numbers are signed or unsigned. •When two unsigned numbers are added, an overflow is detected from the end carry out of the most significant position. •In the case of signed numbers, the leftmost bit always represents the sign, and negative numbers are in 2’s complement form. •When two signed numbers are added, the sign bit is treated as part of the number and the end carry does not indicate an overflow.

Page 11: DATA REPRESENTATION

Overflow example:

+70 0 1000110 -70 1 0111010 +80 0 1010000 -80 1 0110000 = +150 1 0010110 = -150 0 1101010

•An overflow cannot occur after an addition if one number is positive and the other is negative, since adding a positive number to a negative number produces a result that is smaller than the larger of the two original numbers.

•An overflow may occur if the two numbers added are both either positive or negative.

Page 12: DATA REPRESENTATION

Binary Multiplication (Unsigned)

•A complex operation compared with addition and subtraction• Many algorithms are used, esp. for large numbers

• Simple algorithm is the same long multiplication taught in grade school

— Compute partial product for each digit — Add partial products

Page 13: DATA REPRESENTATION

• Multiplication Example 1011 Multiplicand (11 dec)

x 1101 Multiplier (13 dec) 1011 Partial products 0000 1011 1011___ 10001111 Product (143 dec)Note: need double length result• Note: if multiplier bit is 1 copy multiplicand (place

value) otherwise zero.

Page 14: DATA REPRESENTATION

Simplifications for Binary Multiplication

• Partial products are easy to compute:— If bit is 0, partial product is 0— If bit is 1, partial product is multiplicand• Can add each partial product as it is

generated, so no storage is needed• Binary multiplication of unsigned integers• reduces to “shift and add”

Page 15: DATA REPRESENTATION

Control logic and registers• 3 n bit registers, 1 bit carry register CF• Register set up— Q register <- multiplier— M register <- multiplicand— A register <- 0— CF <- 0• CF for carries after addition• Product will be 2n bits in A Q registers

Page 16: DATA REPRESENTATION

Unsigned Binary Multiplication

Page 17: DATA REPRESENTATION

Flowchart for Unsigned Binary Multiplication

Page 18: DATA REPRESENTATION

Booth’s multiplication algorithm

• Bits of the multiplier are scanned one at a a time (the current bit Q0 )• As bit is examined the bit to the right is considered also (the previous bit Q-

1 )• Then:

00: Middle of a string of 0s, so no arithmetic operation.01: End of a string of 1s, so add the multiplicand to the left half of the product (A).10: Beginning of a string of 1s, so subtract the multiplicand from

the left half of the product (A).11: Middle of a string of 1s, so no arithmetic operation.

• Then shift A, Q, bit Q-1 right one bit using an arithmetic shift• In an arithmetic shift, the msb remains unchanged

Page 19: DATA REPRESENTATION

Booth’s Algorithm

Page 20: DATA REPRESENTATION

Example of Booth’s Algorithm (7*3=21)

Page 21: DATA REPRESENTATION

Booth’s Algorithm Registers and Setup

• 3 n bit registers, 1 bit register logically to the• right of Q (denoted as Q-1)• • Register set up• — Q register <- multiplier• — Q-1 <- 0• — M register <- multiplicand• — A register <- 0• — Count <- n• • Product will be 2n bits in A Q registers

Page 22: DATA REPRESENTATION

Floating-Point Representation

•+ 6132.789 is represented in floating-point with a fraction and an exponent as follows:

Fraction Exponent +0.6132789 +04

Scientific notation : + 0.6132789 10+4

Page 23: DATA REPRESENTATION

Floating-Point Representation

• 32-bit floating point format.• Leftmost bit = sign bit (0 positive or 1

negative).• Exponent in the next 8 bits. Use a biased

representation.• Final portion of word (23 bits in this example)

is the significand (sometimes called mantissa).

Page 24: DATA REPRESENTATION

Floating Point Examples

Page 25: DATA REPRESENTATION

3-Bit Signed Integer Representations

Page 26: DATA REPRESENTATION

Other representation

• BCD• Gray codes• Excess-3 Codes

° BCD not very efficient

° Used in early computers (40s, 50s)

° Used to encode numbers for seven-segment displays.

° Easier to read?

Page 27: DATA REPRESENTATION

BCD versus other codes

(Example)

The decimal 99 is represented by 1001 1001.

Page 28: DATA REPRESENTATION

Gray Code• Gray code is not a number

system.– It is an alternative way

to represent four bit data

• Only one bit changes from one decimal digit to the next

• Useful for reducing errors in communication.

• Can be scaled to larger numbers.

Digit Binary Gray Code

0 0000 0000

1 0001 0001

2 0010 0011

3 0011 0010

4 0100 0110

5 0101 0111

6 0110 0101

7 0111 0100

8 1000 1100

9 1001 1101

10 1010 1111

11 1011 1110

12 1100 1010

13 1101 1011

14 1110 1001

15 1111 1000


Recommended