0% found this document useful (0 votes)
51 views24 pages

Slide8-Number Systems and Number Representations

The document discusses number systems and number representations. It covers the following key points: 1) A number system defines a base and set of digits used to represent quantities through positional notation. Different bases like binary, octal, hexadecimal are discussed. 2) Converting between bases like decimal, binary, octal is demonstrated through examples of dividing or grouping bits. 3) Complement notation like (r-1)'s complement and r's complement are introduced as methods for signed number representation and subtraction. 4) Subtraction using r's complement is explained through examples, showing how to find the complement, add it to the minuend, and handle carries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views24 pages

Slide8-Number Systems and Number Representations

The document discusses number systems and number representations. It covers the following key points: 1) A number system defines a base and set of digits used to represent quantities through positional notation. Different bases like binary, octal, hexadecimal are discussed. 2) Converting between bases like decimal, binary, octal is demonstrated through examples of dividing or grouping bits. 3) Complement notation like (r-1)'s complement and r's complement are introduced as methods for signed number representation and subtraction. 4) Subtraction using r's complement is explained through examples, showing how to find the complement, add it to the minuend, and handle carries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

CPNM Lecture 8 - Number Systems and Number

Representations

Mridul Sankar Barik

Jadavpur University

November 22, 2021


Number System

I A number system is merely a convention for representing


quantities
I A base is the number used as the reference for constructing
the system and also defines number of distinct symbols
(digits)
I Different quantities are represented as combinations of the
basic digits, with the position or place value specifying the
magnitude
I Positional notation: dn dn−1 . . . d0 .d−1 d−2 . . . d−m is equal to
dn × b n + dn−1 × b n−1 + . . . + d0 × b 0 + d−1 × b −1 + d−2 ×
b −2 + . . . + d−m × b −m
I A radix point is the symbol used in numerical representations
to separate the integer part of a number from its fractional
part
Binary I
I Base: 2
I Distinct Symbols: 0, 1
I Any binary number an an−1 . . . a0 .a−1 a−2 . . . a−m is equal to
an × 2n + an−1 × 2n−1 + . . . + a0 × 20 + a−1 × 2−1 + a−2 ×
2−2 + . . . + a−m × 2−m in decimal
I Example: (1011)2 = (1 × 23 + 0 × 22 + 1 × 21 + 1 × 20 )2 =
(11)10
I Example: (101011)2 =
(1 × 25 + 0 × 24 + 1 × 23 + 0 × 22 + 1 × 21 + 1 × 20 )2 = (43)10
I Example:
101.011 = 1×22 +0×21 +1×20 +0×2−1 +1×2−2 +1×2−2 =
4 + 0 + 1 + 0 + 41 + 18 = 5 + 0.25 + 0.125 = 5.375
Binary II

I Decimal to Binary
I For the integral part successively divide by 2 until the quotient
is 0; take the remainders in reverse order
I For the fraction part successively multiply by 2 until the
fraction part becomes 0; take the integral part of the products
in order
I Example: Convert 10.625 to binary
Quotient Remainder
10/2 5 0
5/2 2 1
2/2 1 0
1/2 0 1

Table 1: Integral Part

I (10)10 = (1010)2
Binary III
Integral Part
0.625 * 2 1.250 1
0.250 * 2 0.500 0
0.500 * 2 1.000 1

Table 2: Fraction Part

I (0.625)10 =(0.101)2
I (10.625)10 =(1010.101)2
I Binary Addition:
I 0+0=0
I 0+1=1
I 1+0=1
I 1 + 1 = 0 and carry 1
I Example
1 0 1 0
+ 1 1 0 1
1 0 1 1 1
Binary IV
I Example
1 1 1 0 1 1
+ 1 0 1 0 0 1
1 1 0 0 1 0 0
I Binary Subtraction:
I 0−0=0
I 0 − 1 = 1 and borrow 1
I 1−0=1
I 1−1=0
I Example
1 0 1 0
- 0 1 0 1
0 1 0 1
Octal I

I Base: 8
I Distinct Symbols: 0, 1, 2, 3, 4, 5, 6, 7
I Example: (26)8 = (2 × 81 + 6 × 80 )10 = (22)10
I Example: (723)8 = (7 × 82 + 2 × 81 + 3 × 80 )10 =
(448 + 16 + 3)10 = (467)10
I Binary to Octal: group bits from least significant position in
group size of three
I Example: (100101110101)2 = (100 101 110 101)2 = (4565)8
I Add extra zeros in most significant position if number of bits is
not a multiple of three
I Example: (1010110010)2 = (1 010 110 010)2 =
(001 010 110 010)2 = (1262)8
I Example: (1001111010.1010010)2 =
(001 001 111 010.101 001 000)2 = (1172.510)8
Hexadecimal

I Base: 16
I Distinct Symbols: 0, 1, 2, 3, 4, 5 ,6, 7, 8, 9, a, b, c, d, e, f
I Example: (2a)16 = (2 × 161 + 10 × 160 )10 = (42)10
I Example: (3e8)16 = (3 × 162 + 14 × 161 + 8 × 160 )10 =
(768 + 224 + 8)10 = (1000)10
I Binary to Hexadecimal: group bits from least significant
position in group size of four
I Example: (1100101011001011)2 = (1100 1010 1100 1011)2 =
(cacb)16
I Add extra zeros in most significant position if number of bits is
not a multiple of four
I Example: (1001010110010)2 = (1 0010 1011 0010)2 =
(0001 0010 1011 0010)2 = (12b2)16
Numbers with Different Bases
Decimal Binary Octal Hexadecimal
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 a
11 1011 13 b
12 1100 14 c
13 1101 15 d
14 1110 16 e
15 1111 17 f
(r-1)’s Complement I
I To find (r-1)’s complement, subtract each digit of a given
number from the largest digit in that number system
I Example: Find 9’s complement of (7548)10
9 9 9 9
-7 -5 -4 -8
2 4 5 1
I Example: Find 7’s complement of (7543)8
7 7 7 7
-7 -5 -4 -3
0 2 3 4
I Example: Find 15’s complement of 15a7
f f f f
-1 -5 -a -7
e a 5 8
(r-1)’s Complement II

I Example: Find 1’s complement of 1101


1 1 1 1
-1 -1 -0 -1
0 0 1 0
r’s Complement
I To find r’s complement of a given number add 1 to (r-1)’s
complement of that number
I Example: Find 10’s complement of 2394
9 9 9 9
-2 -3 -9 -4
7 6 0 5
+ 1
7 6 0 6
I Example: Find 2’s complement of 1101
1 1 1 1
-1 -1 -0 -1
0 0 1 0
+ 1
0 0 1 1
Subtraction using r’s Complement

I Subtraction of two positive numbers (M-N) both of base r


may be done as follows
I Add the minuend to the r’s complement of subtrahend N
I Inspect the result obtained in step1 for an end carry
I If an end carry occurs discard it
I If an end carry does not occur, take the r’s complement of the
number obtained in step1 and place a negative sign in front
Subtraction using r’s Complement - Example

I Subtract 2957 - 1396


I Find 10’s complement of 1396
9 9 9 9
-1 -3 -9 -6
8 6 0 3
+ 1
8 6 0 4
I Add 8604 to 2956
2 9 5 7
8 6 0 4
1 1 5 6 1
I Discard end carry and the result is 1561
Subtraction using r’s Complement - Example I
I Subtract 1396 - 2957
I Find 10’s complement of 2957
9 9 9 9
-2 -9 -5 -7
7 0 4 2
+ 1
7 0 4 3
I Add 8604 to 2956
1 3 9 6
7 0 4 3
8 4 3 9
I No end carry, so result is negative and is in 10’s complement
form
I Find 10’s complement of 8439
Subtraction using r’s Complement - Example II

9 9 9 9
-8 -4 -3 -9
1 5 6 0
+ 1
1 5 6 1

I So, the result is -1561


Integer Representation I
I Assume that, 3 bits are used for storing integers
I If the integers are unsigned, then there are 8 distinct integer
values that can be stored. Range = 0 to 2n − 1
Integer Value Binary
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111

I If the integers are signed, then most significant bit is used as


the sign bit
I Using Sign Magnitude method for representing signed
numbers. Range = +(2n−1 − 1) to −(2n−1 − 1); Drawback -
Two representations of zero
Integer Value Binary
(Signed Magnitude)
+0 000
+1 001
+2 010
+3 011
-0 100
-1 101
-2 110
-3 111
Integer Representation II
I Using 1’s Complement Method for representing signed
numbers. Range = +(2n−1 − 1) to −(2n−1 − 1); Drawback -
Two representations of zero
Integer Value Binary
(1’s Complement)
+0 000
+1 001
+2 010
+3 011
-3 100
-2 101
-1 110
-0 111

I Using 2’s Complement Method for representing signed


numbers. Range = +(2n−1 − 1) to −(2n−1 ); Single
representation of zero
Integer Value Binary
(2’s Complement)
0 000
+1 001
+2 010
+3 011
-4 100
-3 101
-2 110
-1 111
Floating Point Representation

I A fixed point representation uses fixed number of digits after


the radix point whereas a floating point representation allows
varying number of digits
I Floating point numbers are represented in the form m × b e ,
where m is a fractional part and e an integer part
I m is called a mantissa or significand and e an exponent or
characteristic
1
I Normalization: requires that b ≤m<1
1
I Example: 34 = 0.029411765... can be stored as 0.0294 × 100
in a system that allows four decimal places in mantissa.
However, normalized representation 0.2941 × 10−1 allows us
to retain one additional significant digit
I Source of Error - mantissa holds only a finite number of
significant digits
Floating Point Numbers - Example of a Hypothetical
Machine I
[Taken from Rajaraman]
I Each location can store 6 digits and has provision to store one
or more signs
I Fixed point representation: | 2456 | 24 |
I Max. no. = 9999.99
I Min. no = 0000.01
I Normalized floating point representation:
I Mantissa: less than 1 or greater than equal to 0.1
I Exponent: power of 10 which multiplies mantissa
I Example: 44.85 × 106 = 0.4485 × 108
(+) | 4485 | (+)08 |
I Example: .004854 = 0.4854 × 10−2
(+) | 4854 | (−)02 |
I Range: 0.9999 × 1099 to 0.1000 × 10−99
Floating Point Numbers - Example of a Hypothetical
Machine II
[Taken from Rajaraman]
I Arithmetic operations with normalized floating point numbers
I Addition:
I .4546E5 + .5433E5
Exponents are equal add mantissas, sum = .9979E5
I .4546E5 + .5433E7
Operand with larger exponent is kept as it is
Operand with smaller exponent is shifted right by number of
places equal to the difference in two exponents
.4546E5 + .5433E7 = .0045E7 + .5433E7 = .5478E7
I If the two numbers are m1 × b e1 and m2 × b e2 and e1 < e2
then the first number is transformed as m1 × b −(e2 −e1 ) × b e2
before addition
I .4546E3 + .5433E7 = .0000E7 + .5433E7 = .5433E7
I .6434E3 + .4845E3 = 1.1279E3 = .1127E4
I .6434E99 + .4845E99 = 1.1279E99 = .1127E100
Exponent part cannot store more than two digits ⇒
OVERFLOW
Floating Point Numbers - Example of a Hypothetical
Machine III
[Taken from Rajaraman]
I Subtraction
I .5452E-3 - .9432E-4 = .5452E-3 - .0943E-3 = .4509E-3
I .5452E3 - .5424E3 = .0028E3 = .2800E1
I .5452E-99 - .5424E-99 = .0028E-99 = .2800E-101
Cannot store a number smaller than the smallest number ⇒
UNDERFLOW
I Multiplication:
I (i) multiply the mantissa; (ii) add the exponent; (iii) result
mantissa is normalized and the exponent adjusted
appropriately
I .5543E12 × .4111E-15 = .22787273E-3 = .2278E-3
I .1111E10 × .1234E15 = .01370974E25 = .1370E24
I .1111E51 × .4444E50 = .04937284E101 = .4937E100 ⇒
OVERFLOW
I .1234E-49 × .1111E-54 = .01370974E-103 = .1370E-104 ⇒
UNDERFLOW
Floating Point Numbers - Example of a Hypothetical
Machine IV
[Taken from Rajaraman]

I Division:
I (i) mantissa of numerator is divided by that of the
denominator; (ii) denominator exponent is subtracted from
the numerator exponent; (iii) quotient mantissa is normalized
and exponent adjusted appropriately
I .9998E1 ÷ .1000E-99 = 9.9980E100 = .9998E101 ⇒
OVERFLOW
I .9998E-5 ÷ .1000E98 = 9.9980E-103 = .9998E-102 ⇒
UNDERFLOW
I .1000E5 ÷ .9999E3 = .100010001E2 = .1000E2
Floating Point Numbers - Example I

I Assume 8 bits are used for representation. 1 Sign bit, 3 bits


for exponent and 4 bits for mantissa → b | bbb | bbbb
normalized
I 110.11 −−−−−−→ 0.11011 × 23 → 0 | 011 | 1101
normalized
I 0.01011 −−−−−−→ 0.1011 × 2−1 → 0 | 111 | 1011
normalized
I 0.001011 −−−−−−→ 0.1011 × 2−2 → 0 | 110 | 1011
I When we normalize a decimal fraction, the digit after decimal
point can be any one of 1, 2, ..., 9
I When we normalize binary fraction, the bit after the binary
point is always 1 → so, we can store an extra bit by assuming
that the first bit in the mantissa is always 1 and this bit is not
actually stored
normalized
0.01011 −−−−−−→ 1.0110 × 2−2 → 0 | 110 | 0110
normalized
0.001011 −−−−−−→ 1.0110 × 2−3 → 0 | 101 | 0110

You might also like