Number System
Computer circuits are electronic circuits and are two-state
circuits, OFF and ON state.
In decimal system weights are fixed and position dependent
e.g. 1) 543
3 x 100 = 3
4 x 101= 40
5 x 102= 500
Number System
2) 4 0 7 . 1 5
102 101 100 10-1 10-2
Position of digit is contributing to its value.
Weights of position has got fixed value.
Number System
In binary system different positions have free values. Position
values are in powers of two’s.
e.g.
1 0 1 0 1
24 23 22 21 20
1 1 1 0.1 1
23 22 21 20 2-1 2-2
Number System
Convert the following into binary system.
(26)10
(0.75)10
(0.6)10
Number System
Addition and Subtraction of Binary Numbers
Add 1011 and 1110
Subtract 0111 from 1001
Subtract 1011 from 1100
Number System
Multiplication and Division
Multiply 101 and 011
Divide 11001 by 101
Number System
In octal system base is 8 and eight different symbols are used i.e. 0, 1, 2, 3, 4, 5, 6,
7.
In hexadecimal system base is 16 and symbols used are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E, F.
Problems:
Convert (561)10 to octal number.
Convert (566)10 and (4651)10 to hexadecimal.
Convert (122B)16 to decimal.
Convert (236)16 to decimal.
Convert (1061)8 to decimal.
Convert (72.6)10 to octal and hexadecimal numbers.
Number System
Binary to octal
(11010.1011)2
011010.101100
3 2 . 5 4
i.e. (32.54)8
Number System
Octal to binary
(2 0 7)8
(010000111)2
( 6 1 5 . 7 2 )8
(110001101.111010)2
Number System
Hexadecimal to binary
( 6 A 5)16
(011010100101)2
(1 0 0 . A 2 )16
(000100000000.10100010)2
Number System
Binary to hexadecimal
(1011001.10111)2
01011001.10111000
5 9 . B 8
(59.B8)16
Number System
There are two methods to convert an octal number to
hexadecimal number or hexadecimal number to octal
number.
1)Convert from octal to decimal and then from decimal to
hexadecimal or reverse.
2)Convert from octal to binary and then from binary to
hexadecimal or reverse.
Number System
Convert (7.2)8 to hexadecimal number.
Convert (59.B8)16 to octal number.
Find the value of b in the following:
1) (52)b = (42)10
2) (152)b = (106)10
Number Representation
1) Signed Magnitude form
2) 1’s complement system
3) 2’s complement system
2’s complement system is most important because
it is mostly used in computer calculations.
Number Representation
1) Signed Magnitude form
Suppose we have 6 bits, one bit is for sign and other five are for number or
magnitude.
One bit is sufficient for + and – sign.
+ → 0 (plus is represented by 0)
- → 1 (minus is represented by 1) sign magnitude
(17)10 = (10001)2
+17 => 010001
-17 => 110001
Greatest +ve number which can be represented in 6-bits in signed magnitude form is +31 = 011111
n
[+(2 – 1) where n= 6-1 bits i.e. magnitude bits only)]
Smallest -ve number which can be represented in 6-bits in signed magnitude form is -31 = 111111
n
[ -(2 – 1) ]
Number Representation
2) 1’s complement system 6-bit Representation:
Representation of positive numbers is same in all the three forms.
+17 => 010001
-17 => 101110
+15 => 001111
-15 => 110000
Greatest number : +31 => 011111
Smallest number : -31 => 100000
8-bit Representation:
Greatest number : +127 => 01111111
Smallest number : -127 => 10000000
Number Representation
3) 2’s complement system
1 byte = 8 bits
+24 = 00011000
-24 = 11101000
Highest +ve number = +127 = 01111111
Smallest -ve number = -128 = 10000000
In 2’s complement system negative zero does not exist. That’s why we can add 1.
Greatest -ve number in 2’s complement is -1 i.e. 11111111
Smallest +ve number in 2’s complement is +0 i.e. 00000000
2 bytes = 16 bits Realistic representation in computer
Highest +ve number = 0111111111111111 = +32767
Smallest -ve number = 1000000000000000 = -32768
Addition and Subtraction in 2’s Complement Form
6 bits Representation
1) 7 -14 = -7
000111 + 110010 = 111001
2) -7 -14 = -21
111001 + 110010 = 101011
3) +7+14 = 21
000111 + 001110 = 010101
4) +25 + 10 = +35 (Beyond the capacity of 6 bits)
011001 + 001010 = 100011 = -29 X
Range of numbers in 6 bits is +31 to -32
5) -25 - 10 = -35 (Beyond the capacity of 6 bits)
100111 + 110110 = 011101 = +29 X
There may be overflow when signs of two numbers are same.
Addition and Subtraction in 2’s Complement Form
8-bit Representation:
1) +47 – 47 = 0
00101111 + 11010001 = 00000000
IEEE 754 standards of Floating Point numbers
The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical
standard for floating-point computation which was established in 1985 by the
Institute of Electrical and Electronics Engineers (IEEE).
IEEE Standard 754 floating point is the most common representation today
for real numbers on computers, including Intel-based PC’s, Macs, and most
Unix platforms.
IEEE 754 standards of Floating Point numbers
IEEE 754 has 3 basic components:
1)The Sign of Mantissa – This is as simple as the name. 0 represents a
positive number while 1 represents a negative number.
2)The Biased exponent – The exponent field needs to represent both positive
and negative exponents. A bias is added to the actual exponent in order to
get the stored exponent.
3)The Normalised Mantissa – The mantissa is part of a number in scientific
notation or a floating-point number, consisting of its significant digits. Here we
have only 2 digits, i.e. 0 and 1. So a normalised mantissa is one with only
one 1 to the left of the decimal point.
Normalized floating point number is in 1.Mantissa format.
IEEE 754 standards of Floating Point numbers
IEEE 754 numbers are divided into two based on the three
components- sign, normalized mantissa and Biased exponent.
1) Single precision: Real numbers 4 bytes representation i.e.
32 bits.
2) Double precision: Real numbers 8 bytes representation i.e.
64 bits.
Numbers which are written in double precision are more
accurate .
IEEE 754 standards of Floating Point numbers
1) Single precision: 32-bit floating point representation.
i) Sign (MSB)
ii) Exponent (8 bits after MSB)
iii) Mantissa (Remaining 23 bits)
Sign bit is the first bit of the binary representation. ‘1’ implies negative
number and ‘0’ implies positive number.
Exponent is decided by the next 8 bits of binary representation.
A bias is added to the actual exponent in order to get the stored exponent.
Bias = 2k-1 -1 where ‘k’ is the number of bits in exponent field.
Thus bias = 28-1 -1 = 128-1 =127 for 32 bits.
Contd..
The number will be accurate upto 23 places in binary
system.
Example: To convert -17.75 into 32-bit floating point representation.
(-17.75)10 = - (10001.11)2
= - 1.000111 x 24 → Normalized Form
(i) Sign = 1
(ii) Biased Representation of exponent:
Bias value = 127
127 + 4 = 131 i.e. 10000011 in binary representation.
(iii) Mantissa = 00011100000000000000000
1 1000 0011 0001 1100 0000 0000 0000 000
Sign Exponent Mantissa
Note: "1" before the decimal point is hidden in the representation of IEEE 754 floating point
word, since it takes up an extra bit location and it can be avoided. It is understood that we
need to append the "1" to the mantissa of a floating point word for conversions are
calculations.
IEEE 754 standards of Floating Point numbers
Double precision or 8 bytes Representation:
The number will be accurate upto 52 places in binary system.
IEEE 754 standards of Floating Point numbers
Double precision Representation:
i) Sign (MSB)
ii) Exponent (11 bits after MSB), Bias value = (2 11-1-1) = 1023
iii) Mantissa (Remaining 52 bits)
(More Accuracy)
The more the bits available in the mantissa the more will be the accuracy.
Double precision Representation:
(-17.75)10 = - (10001.11)2
= - 1.000111 x 24
biased exponent = 1023+4 = 1027
1027 = (10000000011)2
Normalised mantisa = 000111
The IEEE 754 Double precision is:
0001 1100 0000 0000 0000 0000 0000 0000 0000 0000
1 100 0000 0011 0000 0000 0000
This can be written in hexadecimal form C031C00000000000
IEEE 754 standard Floating point multiplication
X1 = (125.125)10
X2 = (12.0625)10
X3= X1 * X2 = (1509.3203125)10
Equivalent floating point binary words are
1) Find the sign bit by xor-ing sign bits of A and B [Sign bit = (0 xor 0) = 0]
Contd..
2) Multiply the mantissa values including the "hidden one". The Resultant
product of the 24 bits mantissas (M1 and M2) is 48bits (2 bits are to the left
of binary point)
If M3 (48) = "1" then left shift the binary point and add "1" to the exponent
else don't add anything. This normalizes the mantissa. Truncate the result to
24 bits. Add the exponent "1" to the final exponent value.
Contd..
3) Find exponent of the result. = E1 + E2 -bias + (normalized exponent
from step 2) = (10000101)2 + (10000010)2 - bias +1
= 133 + 130 - 127 + 1 = 137
4) Final result:
In decimal system, X3=1509.3203125
IEEE 754 standard floating point Addition/Subtraction
A = 9.75
B = 0.5625
Equivalent floating point binary words are
1) Abs (A) > Abs (B)? Yes.
2) Result of Initial exponent E3 = E1 = 10000010 = 130
Contd..
3) E1 - E2 = (10000010 - 01111110) => (130-126)=4
4) Shift the mantissa M2 by (E1-E2) so that the exponents are same for both
numbers.
Contd..
5) If sign bits of both are equal then add the mantissa's
6) Normalization needed? No,
(if Normalization was required for M3 then the initial exponent result E3=E1
should be adjusted accordingly)
Contd..
7) Result
X3 in decimal = 10.3125.
Contd..
8) If we had to perform subtraction, just change the sign bit of X2 to "1",
Then we would have subtracted the mantissas. Since sign bits are not
equal.
IEEE 754 standard floating point Division
Division of IEEE 754 Floating point numbers (X1 / X2) is done by dividing the
mantissas and subtracting the exponents.
X1=127.03125
X2=16.9375
Equivalent floating point binary words are
1) S3 = S1 xor S2 = 0
2) E3 = (E1 - E2) + bias = (10000101) - (10000011)+ (1111111)
= 133-131+127 => 129 => (10000001)
Contd..
3) Divide the mantissas M1/M2
4) Result
X3 in decimal = 7.5