0% found this document useful (0 votes)
21 views26 pages

Chapter-2 (Autosaved)

Uploaded by

dawitsibhat37
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)
21 views26 pages

Chapter-2 (Autosaved)

Uploaded by

dawitsibhat37
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/ 26

Chapter-2

Numerical Data Representations

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

called a nibble. A byte consists of 2 nibbles

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).

A computer allows either a byte or a word to be addressable

Addressable: a particular unit of storage can be retrieved by CPU, according to its location in

memory. A byte is the smallest possible addressable unit of storage in a byte-addressable

computer and A word is the smallest addressable unit of storage in a word-addressable

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

Left most bit is sign bit


0 means positive
1 means negative
+18 = 00010010
One’s Complement Representation
• The one’s complement of a binary number
involves inverting all bits.
• Obtained by complementing each bit of
corresponding +ve number
E.g. 0010  1101
Two’s Complement Representation
• The two’s complement of a binary number
involves inverting all bits and adding 1.
• It is obtained by adding 1 to 1’s complement
• E.g. 0010  1110
Computer Arithmetic
Electronic logic deals with currents that are on or off, it has been found
convenient to represent quantities in binary form to perform arithmetic on a
computer.
Instead having ten different digits, 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9, in binary
arithmetic, there are only two different digits, 0 and 1.
Instead of the digit representing a quantity that is ten times as large, it only
represents a quantity that is two times as large.
Integer Addition and Subtraction
Integer Addition and
Subtraction
Binary Multiplication
Booth’s Algorithm
The second method for binary multiplication Is
called Booth’s algorithm
It handles both positive and negative multipliers
uniformly.

It achieves some efficiency in the number of


addition required when the multiplier has a few
large blocks of 1s.
• Possible arithmetic actions:
00  no arithmetic operation
01  add multiplicand to left half of product
10  subtract multiplicand from left half of product
11  no arithmetic operation
Example
-5x4 M = 1011, –M = 0101, Q = 0100

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:

• Computer representation of a floating-point number


consists of three fixed-size fields as follows.
Cont….
Floating Point numbers with base = 10
(‐1)S x F x 10E

Example: 5.9x1012 , ‐2.6x103 9.1 x 10-28


Only one non‐zero digit left to the point
Floating Point numbers with base = 2
(‐1)S x F x 2E
Example: 1.0101x212 , 1.101 x 2‐18
Only one non‐zero digit left to the point
where
S = Sign
F = Fraction (fixed point number) usually called
Mantissa or Significand
E = Exponent (positive or negative integer)
• The one-bit sign field is the sign of the stored value.
• The size of the exponent field determines the range of

values that can be represented.
• The size of the significand determines the precision of
the representation.
where,
Range: difference between the largest and smallest

More bits for the integer part ⟶ increase range


numbers possible.

Precision: smallest possible difference between any

More bits for the fractional part ⟶ increase precision


two numbers

Take as the simple floating-point model is 14 bits in


length
o The sign filed is one bit
o The exponent field is 5 bits
Example: Express 3210 in the simplified 14-bit
simple floating-point model.
• We know that 32 is 25. So in (binary) scientific
notation 32 = 0.1 x 26.
• Using this information, we put 110 (= 610) in the
exponent field and 1 in the significant as shown.

• Convert (37.625)10 = (100101.101)2 into floating point


representation
1.f× 2m
(100101.101)2 = (1.00101101)2 x 25
S =0, f = 00101101 … 00 , m = 5
0 00101 00101101
Cont…
Consider the following 32-bit pattern 1 1011 0110 011 0000 0000 0000 0000 0000

( −1) 1 × 210110110 −01111111 × 1.011


= − 1.375 × 255
= −49539595901075456.0
= − 4.9539595901075456 × 1016

Consider the decimal number: +105.625. The equivalent binary representation is

+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

You might also like