Module 4 - Number System and IEEE Floating Point Representation
Module 4 - Number System and IEEE Floating Point Representation
• Binary Arithmetic
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus
We use digits
0 to 9 -> 10 symbols (digits) (the decimal system)
What is so special about the number 10?
Nothing!
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
The numbering system for
computers
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Decimal vs Binary vs Octal vs
Hexadecimal: An example
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
How a decimal number is
interpreted?
• Eg.: 357
• Digits -> 3 5 7
• Weights-> 10^2 10^1 10^0
• MSD LSD
• Perform sum over Digits*Weights:
• 3*10^2 + 5*10^1 + 7*10^0
• 357
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Binary numbering system
0s and 1s
Binary digits or bits
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Binary numbering system
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Negative Binary Numbers
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Negative Binary Numbers
• To handle negative numbers: left-most bit used to indicate the sign.
• Known by various names: Most Significant Bit (MSB), sign-bit or high-order
bit
• Positive numbers: MSB is 0
• Negative numbers: MSB is 1
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Signed-magnitude
representation
MSB is the sign as usual
7 bits for the magnitude or the value
Range: -127 to 127
Examples:
109 01101101
-109 11101101
127 01111111
-127 11111111
What about zero?
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
1’s complement
As before, MSB indicates the sign. Range: -127 to 127
Negative no. = one’s complement of the positive no.
Invert all the bits -> 1s to 0s and 0s to 1s
Examples:
15 00001111
-15 11110000
85 01010101
-85 10101010
What about zero?
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
2’s complement
2’s complement of a no. = it’s 1’s complement + 1 Most widely used!!
Range: -128 to 127
Example: calculating the two’s complement representation of -15
Decimal 15 00001111
In one’s complement 11110000
Adding 1 +1
In two’s complement 11110001
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus
Binary Arithmetic
Binary arithmetic rules
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Subtraction using 1CT
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Subtraction using 1CT:
Example 1
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Subtraction using 1CT:
Example 2
-3
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Subtraction using 2 CT
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Subtraction using 2 CT:
Example 1
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Substraction using 2CT:
Example 2
-3
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Addition in 2’s Complement
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Addition in 2’s Complement
Ø Overflows occur when the sum does not fit in the given number of bits
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Real numbers in binary (contd.)
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Floating point representation
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Floating point representation
(contd.)
• BUT…
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE 754 floating point
representation
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE 754 floating point
representation (contd.)
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE floating point
representation
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE floating point
representation
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE floating point
representation
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
IEEE floating point
representation
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Converting numbers to IEEE
format
• Convert and normalize the integer part into binary
• Add the two results and adjust them to produce a proper final
conversion
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Example 1
• 12.375
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Example 2
1 1011 0110 011 0000 0000 0000 0000 0000
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
Example 3
• -105.625
Dept. of Computer Science & Information Systems, BITS Pilani, Pilani Campus
BITS Pilani
Pilani Campus