0% found this document useful (0 votes)
99 views34 pages

Integer Representation

The document discusses different ways of representing integers in binary. It explains that sign-magnitude representation uses the most significant bit as a sign bit but has drawbacks. Twos complement representation negates a number by taking the complement of each bit and adding 1. This allows for efficient addition and subtraction. Floating point representation uses normalization to represent numbers in a form with a sign, significand, and exponent to allow for a wider range of values.

Uploaded by

Shania Harold
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views34 pages

Integer Representation

The document discusses different ways of representing integers in binary. It explains that sign-magnitude representation uses the most significant bit as a sign bit but has drawbacks. Twos complement representation negates a number by taking the complement of each bit and adding 1. This allows for efficient addition and subtraction. Floating point representation uses normalization to represent numbers in a form with a sign, significand, and exponent to allow for a wider range of values.

Uploaded by

Shania Harold
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

+

Integer Representation

 In the binary number system arbitrary numbers can be represented


with:
 The digits zero and one
 The minus sign (for negative numbers)
 The period, or radix point (for numbers with a fractional component)

 For purposes of computer storage and processing we do not have the


benefit of special symbols for the minus sign and radix point

 Only binary digits (0,1) may be used to represent numbers


Sign-Magnitude Representation

• All of these alternatives involve treating the most


There are several alternative significant (leftmost) bit in the word as a sign bit
conventions used to represent • If the sign bit is 0 the number is positive
negative as well as positive integers • If the sign bit is 1 the number is negative

Sign-magnitude representation is the


simplest form that employs a sign bit

• Addition and subtraction require a consideration of


both the signs of the numbers and their relative
Drawbacks: magnitudes to carry out the required operation
• There are two representations of 0

Because of these drawbacks, sign-


magnitude representation is rarely
used in implementing the integer
portion of the ALU
Sign-Magnitude using 3 bits
 Uses the most significant bit as a sign bit
 The remaining 2 bits used to represent the magnitude
 Representation of a negative number obtained by changing the sign bit of
the representation of the corresponding positive number

 The range of numbers represented is -3 to 3

 With n bits the range is -(2(n-1) -1) to 2(n-1) - 1

Positive integer Negative integer


000 zero 100 Negative zero
001 one 101 Negative one
010 two 110 Negative two
011 three 111 Negative three
+
Ones Complement
 Uses the most significant bit as a sign bit
 Take the Boolean complement of each bit of the corresponding positive
number
Ones Complement Representation using 3 bits:

Integer x -x
000 zero 111 -0
001 one 110 -1
010 two 101 -2
011 three 100 -3
+
Ones Complement
 Uses the most significant bit as a sign bit
 Differs from sign-magnitude representation in the way that the other
bits are interpreted

Negation Take the Boolean complement of each bit of the


corresponding positive number
Number of representations of two
zero
Expansion of bit length Add additional bit positions to the left and fill with the
value of the original sign bit
Range using n bits -(2(n-1) -1) to 2(n-1) - 1

Table 10.1a Characteristics of Ones Complement Representation


+
Twos Complement - Negation

 Twos complement operation


 Take the Boolean complement of each bit of the integer (including the sign
bit)
 Treating the result as an unsigned binary integer, add 1

+18 = 00010010 (8-bit twos complement)


bitwise complement = 11101101
+ 1
11101110 = -18

 The negative of the negative of that number is itself:


-18 = 11101110 (8-bit twos complement)
bitwise complement = 00010001
+ 1
00010010 = +18
+
Range Extension

 Range of numbers that can be expressed is extended by increasing the


bit length

 In sign-magnitude notation this is accomplished by moving the sign


bit to the new leftmost position and fill in with zeros

 This procedure will not work for twos complement negative integers
 Rule is to move the sign bit to the new leftmost position and fill in with
copies of the sign bit
 For positive numbers, fill in with zeros, and for negative numbers, fill in
with ones
 This is called sign extension
Addition
Overflow

OVERFLOW RULE:

If two numbers are added,


Rule
and they are both positive or
both negative, then overflow
+ occurs if and only if the result
has the opposite sign.
Subtraction

SUBTRACTION RULE:

To subtract one number


(subtrahend) from another Rule

(minuend), take the twos


+
complement (negation) of the
subtrahend and add it
to the minuend.
Subtraction
+
Twos Complement Representation
 Uses the most significant bit as a sign bit
 Differs from sign-magnitude representation in the way that the other
bits are interpreted

Table 10.1 Characteristics of Twos Complement Representation and Arithmetic


Table 10.2
Alternative Representations for 4-Bit Integers
Review Questions
1

2
Review Questions

3. Convert each of the following decimal


numbers to binary:
31 133 6.75 31.33

4. Convert each of the following binary


numbers to decimal:
11011 101.101 0.00101
Review Questions
5

6
Review Questions
7

8
Fixed-Point Representation

Programmer can use the same


representation for binary
The radix point (binary point) is
fractions by scaling the numbers
fixed and assumed to be to the
so that the binary point is
right of the rightmost digit
implicitly positioned at some
other location
+
Floating-Point Representation
Principles
 With a fixed-point notation it is possible to represent a range of
positive and negative integers centered on or near 0

 By assuming a fixed binary or radix point, this format allows the


representation of numbers with a fractional component as well

 Limitations:
 Very large numbers cannot be represented nor can very small fractions
 The fractional part of the quotient in a division of two large numbers could
be lost
+
Normalization
 To simplify operations on floating-point numbers, it is typically required that
they be normalized.

 For Decimal numbers: 


123.456 is normalized to 0.123456 x 103

 For Binary Numbers:


-0.0000145 is normalized to – 0.145 x 10 -4

 Essential features are sign, fractional part, base and exponent.

 If the base is known we need only store the sign, fractional part (called the
significand) and exponent.
+
Normalization
 A normalized number is one in which the most
significant digit of the significand is nonzero.
 Forbase 2 representation, a normalized number is
therefore one in which the most significant bit of
the significand is one.
 1011.11 is normalized to 0.101111 x 24

 -.0000011011 is normalized to -0.11011 x 2 -5


+
Normalization
 However,in the IEEE754 standard, binary numbers
are normalized to the form:
±1.b1b2b3… x 2 exp
where bi is 0 or 1 for i = 1,2,3,…
1011.11 is normalized to 1.01111 x 23

-.0000011011 is normalized to -1.1011 x 2 -6


 Only the sign, significand and exponent are stored

Sign bit Exponent field Significand field


+
Example
Write down the normalized form of each binary
number below using the IEEE 754 Standard:
a. -10001.101
b. .00011101
c. -1011.11 x 23
d. 110.011 x 2-3
IEEE 754
Formats
Typical 32-Bit Floating-Point Format
+
IEEE754 standard
Sign bit Exponent field Significand field

 Theleftmost bit stores the sign of the number (0


= positive, 1 = negative).
 Theexponent value is stored in the next k bits.
The representation used is known as a K-bit
biased representation.
 A fixedvalue, called the k-bit bias, is subtracted
from the field to get the true exponent.
+
Biased Representation of Exponent
the bias equals (2k-1 - 1), where k is the number of
bits in the binary exponent.

Biased exponent = actual exponent + bias

Let k = 4. A 4-bit field yields the numbers 0 to 15.


The 4-bit bias = (2(4-1) - 1) = 7

The true exponent values are in the range -7 to +8.


+ The table below shows the biased representation for 4-bit
integers.
Decimal Biased Rep Decimal Biased Rep.
-7 0000 1 1000
-6 0001 2 1001
-5 0010 3 1010
-4 0011 4 1011
-3 0100 5 1100
-2 0101 6 1101
-1 0110 7 1110
0 0111 8 1111

• The bits of a biased representation are treated as unsigned integers

• The relative magnitudes of the numbers do not change.


+
Biased Exponent

An advantage of biased representation is


that nonnegative floating-point numbers can
be treated as integers for comparison
purposes
+Assume a 9-bit floating point format: sign bit,
followed by a 4 bit biased exponent and a 4-bit normalized
significand.

Given a 9-bit floating point rep: 10010 0100


a. What is the sign, biased exponent and significand?
b. What is the 4-bit bias?
c. What is the biased exponent and true exponent?
d. What is the denormalized binary number?
e. What is the decimal number represented?
• Determine the range of numbers represented.
• What is the representation of 3?
• Can 16.5 be stored accurately?
• What is the effect of increasing size of significand field?
• What is the effect of increasing size of exponent field?
+
Expressible Numbers
+
Notes
• The representation as presented will not accommodate a
value of 0.

• actual floating-point representations include a special bit


pattern to designate zero.

• Overflow occurs when an arithmetic operation results in


an absolute value greater than can be expressed with a k-
bit biased exponent.

• Underflow occurs when the fractional magnitude is too


small. Underflow is a less serious problem because the
result can generally be satisfactorily approximated by 0.
+
Notes
• We are not representing more individual values with
floating-point notation.

• The maximum number of different values that can be


represented with 32 bits is still 232.

• What we have done is to spread those numbers out in two


ranges, one positive and one negative.

• Most floating-point numbers that one would wish to


represent are represented only approximately.

• However, for moderate sized integers, the representation


is exact.
IEEE Standard 754

Standard was developed to


facilitate the portability of
Most important floating-point programs from one processor to
representation is defined another and to encourage the
development of sophisticated,
numerically oriented programs

Standard has been widely


IEEE 754-2008 covers both
adopted and is used on virtually
binary and decimal floating-point
all contemporary processors and
representations
arithmetic coprocessors

You might also like