Number Representation: CHAPTER 3 - Part 3

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 52

NUMBER

REPRESENTATION
CHAPTER 3 – part 3
ONE’S COMPLEMENT
REPRESENTATION
CHAPTER 3 – part 3
Integer Representation

Integer
Representation

Unsigned Signed

Sign and One’s Two’s


Magnitude Complement Complement
One’s complement integers

To represent
positive number same way as UNSIGNED Integer

negative number complement the positive


One’s complement integers

Table 3.5 Range of One’s complement integers

# of Bits Range
--------- -------------------------------------------------------
8 -127 -0 +0 +127
16 -32767 -0 +0 +32767
32 -2,147,483,647 -0 +0 +2,147,483,647
One’s complement integers

There are two 0s in One’s complement


representation: positive and negative.

In an 8-bit allocation:
+0  00000000
-0  10000000
One’s complement integers

In one’’s complement representation,


the leftmost bit defines the sign of the
number.
If it is 0, the number is positive.
If it is 1, the number is negative
One’s complement integers
Storing One’s complement integer process:

1. The integer is changed to binary, (the sign is


ignored).
2. 0s are added to the left of the number to make a
total of N
3. bits
4. If the sign is positive, no more action is needed. If
the sign is negative, every bit is complemented
Example 4

Store +7 in an 8-bit memory location using one’s


complement representation.
Solution

 The integer is changed to binary (111).


 Add 5 0s to make a total of N (8) bits,
00000111 .
 The sign is positive so no more action is needed
Example 5

Store –258 in a 16-bit memory location using one’s


complement representation
Solution
 First change the number to binary 100000010.

 Add 7 0s to make a total of N (16) bits,


0000000100000010.
The sign is Negative so each bit is complemented
0000000100000010
One’s complement integers

Table 3.6 Example of storing one’s complement integers


in two computers
Decimal 8-bit allocation 16-bit allocation
------------ ------------ ------------------------------
+7 00000111 0000000000000111
−7 11111000 1111111111111000
+124 01111100 0000000001111100
−124 10000011 1111111110000011
+24,760 overflow 0110000010111000
−24,760 overflow 1001111101000111
One’s complement integers

1. If the left most bit is 0 (positive number)


A. Change the entire number from binary to decimal
B. Put a positive sign(+) in front of the number
2. If the left most bit is 1 (negative number)
A. Complement the entire number (change all 0’s to 1’s and vice versa)
B. Change the entire number from binary to decimal
C. Put a negative sign(-) in front of the number
Example 6

Interpret 11110110 to decimal if the number was


stored as a one’s complement integer.

Solution
the leftmost bit is 1, so the number is negative
Complement the number 11110110 00001001
the complement in decimal is 9
So the answer is -9
One’s complement Applications
The one’s complement representation is not used now
by computers because:

Operations: such as subtraction and addition is not 

straightforward for this representation.

Uncomfortable in programming: because there are 

two 0s in this representation


One’s complement Applications
However..
The advantage of this representation is:
1. It’s the foundation of the next representation(Two’s
complement)
2. It has properties that make it interesting for data
communication applications such as error detection
and correction
TWO’S COMPLEMENT
REPRESENTATION
Integer Representation

Integer
Representation

Unsigned Signed

Sign and One’s Two’s


Magnitude Complement Complement
Two’s complement integers

It’s…
The most common
The most important
The most widely used representation today
Two’s complement integers

Table 3.7 Range of Two’s complement integers

# of Bits Range
--------- -------------------------------------------------------
8 -128 -0 +0 +127
16 -32768 -0 +0 +32767
32 -2,147,483,648 -0 +0 +2,147,483,647
Two’s complement integers

There is Only one 0 in Two’s complement


representation

In an 8-bit allocation:
0  00000000
Two’s complement integers

In two’s complement representation,


the leftmost bit defines the sign of the
number.
If it is 0, the number is positive.
If it is 1, the number is negative
Two’s complement integers
Storing One’s complement integer process:

1. The number is changed to binary, (the sign is


ignored).
2. 0s are added to the left of the number to make a
total of N bits
3. If the sign is positive, no more action is needed. If
the sign is negative, leave all the rightmost 0’s and
the first 1 unchanged. Then complement the rest of
the bits.
Example 4

Store +7 in an 8-bit memory location using two’s


complement representation.
Solution

 The integer is changed to binary (111).


 Add 5 0s to make a total of N (8) bits,
00000111 .
 The sign is positive so no more action is needed
Example 5

Store –40in a 16-bit memory location using two’s


complement representation
Solution
 First change the number to binary 101000.

 Add 10 0s to make a total of N (16) bits,


0000000000101000.
 The sign is Negative so leave the rightmost 0’s up
to the first 1
0000000000101000 1000
Two’s complement integers

Table 3.8 Example of storing two’s complement integers


in two computers
Decimal 8-bit allocation 16-bit allocation
------------ ------------ ------------------------------
+7 00000111 0000000000000111
−7 11111001 1111111111111001
+124 01111100 0000000001111100
−124 10000100 1111111110000100
+24,760 overflow 0110000010111000
−24,760 overflow 1001111101001000
Two’s complement integers

1. If the left most bit is 0 (positive number)


A. Change the entire number from binary to decimal
B. Put a positive sign(+) in front of the number
2. If the left most bit is 1 (negative number)
A. leave the rightmost 0’s up to the the first 1 unchanged. Complement
the rest bits.
B. Change the whole number from binary to decimal
C. Put a negative sign(-) in front of the number
Example 6

Interpret 11110110 to decimal if the number was


stored as a two’s complement integer.

Solution
the leftmost bit is 1, so the number is negative
Leave 10 at the right alone and Complement the rest
11110110 00001010
the complement in decimal is 10
So the answer is -10
Two’s complement Applications
The two’s complement representation is the standard
representation used for storing integers by computers
today because it makes the operations simple.
SUMMARY OF INTEGER
REPRESENTATION
•Unsigned
•Sign & magnitude

•One’s complement

•Two’s complement
Contents of Sign & One’s Two’s
Unsigned
Memory magnitude complement complement
0000 0 +0 +0 +0
0001 1 +1 +1 +1
0010 2 +2 +2 +2
0011 3 +3 +3 +3
0100 4 +4 +4 +4
0101 5 +5 +5 +5
0110 6 +6 +6 +6
0111 7 +7 +7 +7
1000 8 -0 -7 -8
1001 9 -1 -6 -7
1010 10 -2 -5 -6
1011 11 -3 -4 -5
1100 12 -4 -3 -4
1101 13 -5 -2 -3
1110 14 -6 -1 -2
1111 15 -7 -0 -1
EXCESS SYSTEM
Excess System

It's another representation that allows you to store both
positive and negative numbers in a computer

the
‰ magic number a positive number
used in the conversion process
‰ = N OR N

where N is the bit allocation



The bit allocation :is the number of bits used to represent
an integer
Example
If N= 8 bits .Calculate the magic number.

Answer:
= N OR N

= 8 OR 8

= OR
EXCESS_127 EXCESS_128
Excess System Representation
To represent a number in Excess, use the following
procedure:
 ‰Add the magic number to the integer
 ‰Change the result to binary and add 0s so that
there is a total of N bits
Excess System Representation
Example:
Represent –25 in Excess_127 using an 8-bit
allocation.

Answer:
127 + (-25) = 102
102
add 0’s to the left to make it 8 bit
01100110
Excess System Interpretation
To interpret a number in Excess, use the following
procedure:
 ‰
Change the number to decimal
 Subtract the magic number from the integer
Excess System Interpretation
Example:
Interpret 11111110 if the representation is
Excess_127.

Answer:
11111110
254 – 127 = 127
FLOATING POINT
REPRESENTATION
Floating point representation

Floating point number = a number containing


an integer & a fraction

Example: 14.234

Integer Fraction
Convert from Floating point number to
binary
1. Convert the integer part to binary
2. Convert the fraction to binary

3. Put a decimal point between the two parts

Convert from Floating point number to
binary
Example
Transform the fraction 0.875 to binary

Answer:
Write the fraction at the left corner.
Multiply the number continuously by 2 and extract the
integer part as the binary digit. Stop when the
number is 0.0.
fraction 0.875  1.750  1.50  1.0  0.0

binary 0. 1 1 1
Convert from Floating point number to
binary
Example
Transform the fraction 0.4 to a binary of 6 bits.

Answer:
Write the fraction at the left cornet.
Multiply the number continuously by 2 and extract the integer part as
the binary digit.
You can never get the exact binary representation. Stop when
you have 6 bits

fraction 0.4  0.8 1.6  1.2  0.4  0.8  1.6

binary 0. 0 1 1 0 0 1
NORMALIZATION
Normalization
A fraction is normalized so that operations are
simpler

Normalization:
the moving of the decimal point so that there is
only one 1 to the left of the decimal point.
Normalization

Original Number Move Normaliazed


+ 1010001.11001 6 + 26 x 1.01000111001
- 111.000011 2 -2 2 x 1.110011
+ 0.00000111001 6 +2-6 x 1.11001
- 0.001110011 3 -2-3 x 1.110011
Normalization
After the number is normalized we store 3 pieces of
information about it:
SIGN EXPONENT MANTISSA

Example:
+ 26 x 1.0001110101

SIGN EXPONENT MANTISSA


IEEE standard for floating point
representation
Single-Precesion Representation
The procedure of storing a normalized floating point
number using single precession format is as follow:

1. Store the sign as 0 (positive) or 1 (negative)


2. Store the exponent (power of 2) as Excess_127
3. Store the mantissa as unsigned integer
EXAMPLE
 Show the representation of the normalized number
+ 26 x 1.01000111001

ANSWER:

The sign is positive.


The Excess_127 representation of the exponent is 133.
You add extra 0s on the right to make it 23 bits. The
number in memory is stored as:
0 10000101 01000111001000000000000

SIGN EXPONENT MANTISSA


Example of floating point
representation

Number Sign Exponent Mantissa


-2 2 x 1.11000011 1 10000001 11000011000000000000000
+2-6 x 1.11001 0 01111001 11001000000000000000000
-2-3 x 1.110011 1 01111100 11001100000000000000000
Floating point Interpretation for single
precision
the following procedure interprets a 32-bit floating-point
number stored in memory
1. Use the leftmost bit as the sign
2. Change the next 8 bit to decimal and subtract 127
from it. (this is the exponent)
3. Add 1 and a decimal point to the next 23 bits (ignore
any extra 0’s in the right)
4. Move the decimal point to the correct position using
the value of the exponent
5. Change the whole part to decimal
6. Change the fraction part to decimal
7. Combine the whole and the fraction parts
Example
Interpret the following 32-bit floating-point
number

1 01111100 11001100000000000000000

ANSWER:
The sign is negative.
The exponent is –3 (124 –127).
The number after normalization is
-2-3 x 1.110011

You might also like