Chapter-2 (Autosaved)
Chapter-2 (Autosaved)
Contents
Number Representation
Fixed point/Integer representation
Floating point representation
Computer Arithmetic
Addition & subtraction
Division and Multiplication
Booth algorithm
Introduction
In a computer, a bit could be either “1” or “0”. A byte is a group of 8 bits. A group of 4 bits is
A word is a group of bytes. Words can be any number of bits or bytes. According to different
computer systems, the size of word could be 2 bytes (16 bits), 4 bytes (32 bits), or 8 bytes (64
bits).
Addressable: a particular unit of storage can be retrieved by CPU, according to its location in
computer
Number Representation
• Based on the number system, two basic
datatypes are implemented in computer system:
Fixed Point Numbers
Floating Point Numbers
Rep
rese
Fixe ntat
d Po ion
Signed Integer int
Unsigned Integer
/inte
two forms:
gers
Fixed Point Numbers (Integers) are represented in
Integer representation
• The set { . . . , –3, –2, –1, 0, 1, 2, 3, . . . } of
integers is also referred to as signed numbers.
• The most straightforward representation of
integers consists of attaching a sign bit to any
desired representation of natural numbers,
leading to signed magnitude representation.
• The standard convention is to use 0 for positive
and 1 for
negative and attach the sign bit to the left end of
the magnitude.
Unsigned Integer
• It is fixed point system with no fractional digits.
• Does not have provision for negative numbers
• E.g. A 4-bit unsigned integer has values ranging
from 0000(010) to 1111(1510)
How to represent Signed Numbers?
• Plus and minus signs used for decimal numbers:
25 or +25, -16 or +16, etc.
• For computers, it is desirable to represent
everything as bits.
• Three types of signed binary number
representations:
Signed magnitude,
1’s complement, and
2’s complement
Signed magnitude,
000100102 = 1810 100100102 = -1810
Look at the sign bit and magnitude of 18 &-18
Sign bit
Magnitude
Sign bit Magnitude
A Q Q -1 operation
0000 0100 0 initial
0000 0010 0 ASR
0000 0001 0 ASR
0101 0001 0 A A-M
0010 1000 1 ASR
1101 1000 1 A A+M
1110 1100 0 ASR
Floating point representation
• Most of today’s computers are equipped with
specialized hardware that performs floating-
point arithmetic with no special programming
required
• Floating-point numbers allow an arbitrary
number of decimal places to the right of the
decimal point.
For example: 0.5 0.25 = 0.125
• They are often expressed in scientific notation.
For example:
0.125 = 1.25 10-1
5,000,000 = 5.0 106
• Computers use a form of scientific notation for
floating-point representation
• Numbers written in scientific notation have
three components:
+1101001.101
= +1.101001101 × 2 6
= +1.101001101 × 2133 −127
= + 1.101001101 × 210000101 −01111111
IEEE 754 Floating point
Standard
• Two standards:
• Single Precision Representation
• Double Precision Representation
Single Precision Representation
• 32-bit representation
• Divided into 3 fields :
• Sign : 1-bit
• Exponent : 8-bit
• Mantissa : 23-bits
• Instead of signed exponent, the value stored in
exponent field is E = E + bias
• Bias for 32-bit is 127, it is called excess-127
format
Double Precision
Representation
• 64-bit representation
• Divided into 3 fields :
• Sign : 1-bit
• Exponent : 11-bit
• Mantissa : 52-bits
• Exponent field is E = E + bias
• Bias for 64-bit is 1023, it is called excess-1023
format
Example:
(85.125)
10
85 = 1010101
0.125 = 001
85.125 = 1010101.001
=1.010101001 x 2^6
sign = 0.
1. Single precision:
biased exponent 127+6=133, 133 = 10000101 Normalised mantisa =
010101001 we will add 0's to complete the 23 bits.
The IEEE 754 Single precision is: = 0 10000101
01010100100000000000000
2. Double precision:
biased exponent 1023+6=1029 1029 = 10000000101 Normalised mantisa
= 010101001 we will add 0's to complete the 52 bits
The IEEE 754 Double precision is:
0 10000000101
0101010010000000000000000000000000000000000000000000
Problems
Represent 1259.125; -307.1875; 0.0625in single precision
and double precision format
Special values