Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 Integer Data Representation. Unsigned Integers.

Similar presentations


Presentation on theme: "Chapter 4 Integer Data Representation. Unsigned Integers."— Presentation transcript:

1 Chapter 4 Integer Data Representation

2 Unsigned Integers

3 Range of Values l 1 Byte: 0-255 l 2 Bytes:0-65,535 l 4 Bytes:4,294,967,295 l 8 Bytes:2 64 - 1

4 Implementation l Generally, built-in machine instructions exist for manipulating and calculating single-precision (32 bit) or double precision (64 bit) integers l If not, software procedures may exist to handle multiple storage locations for integers

5 Signed Integers l Signed-Magnitude l 1’s Complement l 2’s Complement NOTE: Only latter is typically implemented due to serious limitations of others.

6 Signed-Magnitude l Choose a single bit to represent the sign - usually most significant bit l 0 => + and 1=>negative l Maximum absolute value is 2 31 -1 (assuming 32 bit representation)  2,147,483,647

7 Problems l In arithmetic operations, must test signs of both operands to determine process l Two zeroes exist:  0 Thus, comparison of 0s becomes an issue

8 Complements Representation The sign of the number is a natural result of the arithmetic operations, and therefore the sign does not have to be handled separately. Calculations are consistent for all different signed combinations of the operands.

9 1’s Complement l Numbers whose binary representation begins with a 0 are considered positive and those that begin with a 1 are negative l To get the negative representation of a positive number, one takes the complement of the number

10 1’s Complement 8-bit representation

11 Observations l Range of number values is split in the middle l Even numbers begin with 0 and positive numbers with 1 l To add numbers, regardless of sign, one just does a regular addition (wraparound) l Suppose a negative and positive number are added. End-around carry may result. l Overflow can occur

12 Basis for 1’s Complement Subtracting a value from some standard base value is known as taking the complement. In binary representation for 8-bits, say, we would subtract a positive number from 11 111 111 in order to derive its negative representation. Example -58:11 111 111 -00 111 010 ======== 11 000 101 NOTE: The negative is just the inversion of the positive number.

13 1’s Complement Addition 5800 111 01010601 101 010 +2200 010 110 - 211 111 101 ===================== 8001 010 000 1  01 100 111 1  end-around 6401 000 000======== carry +6501 000 00110401 101 000 == ======== 12910 000 001 => overflow => result exceeded range of values

14 1s Complement Testing for Overflow If both operands have the same sign and the sign of the result is different, then overflow has occurred. NOTE: Some early interpreted versions of Pascal limited word size to 16 bits. When the interpreter was subsequently executed on 32-bit machines, overflow was not detected.

15 1’s Complement Problems Addition may require end-around carry. Two zeroes exist:  0 Thus, comparison of 0’s becomes an issue

16 2’s Complement Representation

17 Basis for 2’s Complement The modulus in 2’s complement is a 1 followed by a string of 0’s. In binary representation for 8-bits, say, we would subtract a positive number from 100 000 000 in order to derive its negative representation. Example -58: 100 000 000 -00 111 010 ======== 11 000 110 NOTE: The negative representation is just the inversion of the positive number plus 1.

18 2’s Complement Addition 5800 111 01010601 101 010 +2200 010 110 - 211 111 110 ===================== 8001 010 000 104 1  01 101 000ignore carry bit 6401 000 000 +6501 000 001 == ======== 12910 000 001 => overflow => result exceeded range of values

19 2s Complement Testing for Overflow An overflow has occurred if when the result overflows into the sign bit. Thus overflow can be detected if the sign of the result is opposite that of both operands. A carry-out bit is ignored.


Download ppt "Chapter 4 Integer Data Representation. Unsigned Integers."

Similar presentations


Ads by Google