Mod 2
Mod 2
Dr. C.R.Dhivyaa
Assistant Professor
School of Computer Science and Engineering
Vellore Institute of Technology, Vellore
Number System & Types
• In digital electronics, the number
system is used for representing the
information.
• Number system - different bases
• The base or radix of the number
system is the total number of the
digit used in the number system.
Binary Number Systems
• Characteristics
• It holds only two values, i.e., either 0 or 1.
• It is also known as the base 2 number system.
• The position of a digit represents the 0 power of
the base(2). Example: 20
• The position of the last digit represents the x
power of the base(2). Example: 2x, where x
represents the last position.
• Examples: (10100)2, (11011)2, (11001)2, (000101)2,
Binary Number Systems
• Terminologies - Binary systems
• Each digit – 1 Bit – 0/1 - Single Binary Digit
• Collection of 4 bits - Nibble
• Collection of 8 bits - Byte
• Collection of 16/32/64 bits - Word
Depends on Memory
Organization of a
Computer
Decimal Number Systems
• Contains ten digits from 0 to 9
• base 10 number system
• The successive place value or position, left
to the decimal point holds units, tens,
hundreds, thousands, and so on.
Octal Number Systems
• Contains Eight digits from 0 to 7
• base 8 number system
• Octal number – represented in only 3 bits.
• The position of a digit represents the 0
power of the base(8). Example: 80
• The position of the last digit represents the
x power of the base(8). Example: 8x, where
x represents the last position.
• Examples:
(273)8, (5644)8, (0.5365)8, (1123)8, (1223)8.
Hexadecimal Number Systems
• Contains ten digits from 0 to 9 and 6 letters from A to
F.
• The letters from A to F defines numbers from 10 to 15.
• base 16 number system.
• The position of a digit represents the 0 power of the
base(16). Example: 160
• The position of the last digit represents the x power of
the base(16). Example: 16x, where x represents the
last position.
• Examples: (FAC2)16, (564)16, (0ABD5)16, (1123)16, (11F3)16.
Number Systems
• Numbers
• Unsigned Numbers (+)
• has only magnitude - no sign.
• Signed Numbers(+/-)
• has both magnitude and sign
• Sign bit – 0 – positive number
• Sign bit – 1 – Negative number
• Representing Binary Numbers
• n bits – can be used to represent--- 2n distinct numbers (0 to 2n-1)
▪ For example: If n=3 bits, 23 = 8 distinct numbers (0 to 7)can be represented
▪ (0-000, 1-001, 2-010, 3-011, 4-100, 5-101, 6-110, 7-111)
Unsigned Number Representation of 4 Bits
• If no. of bits → 4, Unsigned → 0 to 2n-1
• then for unsigned numbers, these four bits can store the decimal values from
0 to 24-1 → (decimal values 0 to 15).
No. of Unsigned numbers that can be stored in
bits (n) n bit representation
3 Decimal Numbers 0 to 7 0 to 23-1
4 D. Numbers 0 to 15 0 to 24-1
5 D. Numbers 0 to 32 0 to 25-1
6 D. Numbers 0 to 63 0 to 26-1
7 D. Numbers 0 to 127 0 to 27-1
8 D. Numbers 0 to 255 0 to 28-1
……. …… ……
Unsigned → 0 to 2n-1
Signed (Sign Magnitude Representation)→-2n-1+1 to 2n-1-1
Signed (One’s Complement Representation)→-2n-1+1 to 2n-1-1
Signed (Two’s Complement Representation)→-2n-1 to 2n-1-1
Sign Magnitude Representation of 4 Bits
Sign-Magnitude Representation
Advantages Expansion of Bit Length: Add additional bit positions to the left
• Unique representation of 0. and fill in with the value of the original sign bit.
• Subtraction can be done using addition. Overflow Rule: If two numbers with the same sign (both positive or
• Leads to substantial saving in circuitry. both negative) are added, then overflow occurs if and only if the
result has the opposite sign.
Two’s Complement Representation of Signed Numbers
• Example: How to represent -4 using 2’s complement representation??
• No. of bits required to represent signed - 4 is 3 bits + 1 sign bit
• Signed representation of +4=0100
• 1’s complement representation of -4 is –(0100) is 1011.
• 2’s complement representation → 1011
+ 1
=1100
• Here again the most significant bit will indicate the sign 0 for positive,
1 for negative.
To conclude: Pros and cons of integer representation
• Signed magnitude representation:
• 2 representations for 0
• Simple
• 255 different numbers can be represented.
• Need to consider both sign and magnitude in arithmetic
• Different logic for addition and subtraction
• 1’s complement representation:
• 2 representations for 0
• Complexity in performing addition and subtraction
• 255 different numbers can be represented.
• 2’s complement representation:
• Only one representation for 0
• 256 different numbers can be represented.
• Arithmetic works easily
Real/Fractional Number Notation
• Real Numbers - numbers with fractional component
• Two major approaches to store real numbers
• Fixed Point Notation
• Floating Point Notation.
• Fixed point notation - there are a fixed number of digits after the decimal
point (Integer . Fraction)
• In this representation the position of the radix point is fixed. Hence this
representation is called fixed point representation
• Example: (123.431), (4.5)10 = (100.1)2
• Floating point number - allows for a varying number of digits after the
decimal point. (Integer . Fraction)
• In this representation the position of the radix point is allowed to move.
• Example: (-123.334444455555567),
Real Number Notation
Fixed Point Representation
• The number of integer and fraction bits must be agreed upon by
those generating and those reading the number
• Example: Fixed-point representation of 6.75 using 4 integer bits
and 4 fraction bits in binary
• 6 =110 -→ 0110
• .75 = 110 → 1100
• Binary Representation:
01101100
(6.75)10 = (0110.1100)2
• Convert back to Decimal (Check)
0*23 + 1*22 + 1*21 + 0*20 + 1*2-1 + 1*2-2 + 0*2-3 + 0*2-4
= 6.75
Fixed Point Representation
Fixed Point Binary Numbers - Arithmetic
Operations
• Addition
• Subtraction
• Multiplication
• Division
Fixed Point Binary Numbers - Addition
• Follow same rules as in decimal addition, with the difference that when
sum is 2 indicates a carry (not a 10)
• Carry rules Carry 1 1 1 1 1 0
• 0+0 = sum 0 carry 0 Augend 0 0 1 0 0 1
• 0+1 = 1+0 = sum 1carry 0 Addend 0 1 1 1 1 1
• 1+1 = sum 0 carry1 Result 1 0 1 0 0 0
• 1+1+1 = sum 1 carry1
• Multiplication of two unsigned binary numbers of n bit size results into 2n bit
result.
N * N bits input = 2N bits result
Fixed Point Binary Numbers -
Multiplication
Unsigned Integer representation
• n bit - How many distinct numbers can be represented?
• 2n – Distinct numbers.
▪ For example:
▪ If n=3 bits,
23 = 8 (0-000, 1-001, 2-010, 3-011, 4-100, 5-101, 6-110, 7-111)
▪ 0 is minimum and 7 (2n-1) is maximum
▪ If n=4 bits,
24 = 16 (0 to 15)
▪ 0 is minimum and 15 is maximum
▪ If n=5 bits,
25 = 32 (0 to 31)
▪ 0 is minimum and 31 is maximum
▪ If n=6 bits,
26 = 64 (0 to 63)
▪ 0 is minimum and 63 is maximum
Multiplication of unsigned numbers
1. Multiply the given numbers 13 x 11
• number of bits required to represent the number 13 is 4 bits
• number of bits required to represent the number 11 is 4 bits
• Convert decimal to binary
• 13→ 1101
• 11→1011
Multiplication of unsigned numbers
1. Multiply the given numbers 13 x 11
27 26 25 24 23 22 21 20
Multiplicand is shifted by
displacing it through an
array of adders.
Multiplication of Signed numbers
Signed number representation
• For an n bit representation: MSB- sign bit(0 or 1), n-1(magnitude)
0 0 0 0 0 1 1 0 1
Sign extension is
shown in red
0 0 0 0 0 0 0 0
0 0 0 1 1 0 1
0 0 0 0 0 0
0 0 1 0 0 0 1 1 1 1 ( + 143 )
- 29 28 27 26 25 24 23 22 21 20
= (0*-29)+ (0*28)+ (1*27)+(0*26)+(0*25)+(0*24)+(1*23)+(1*22)+(1*21)+(1*20)
=128+8+4+2+1 =143→ answer
Multiplication of Signed numbers
• Case 2: Multiply the given numbers (-13) x (+11) (Positive Multiplier)
1 1 1 1 1 1 0 0 1 1
1 1 1 1 1 0 0 1 1
Sign extension is
0 0 0 0 0 0 0 0 shown in red
1 1 1 0 0 1 1
0 0 0 0 0 0
1 1 0 1 1 1 0 0 0 1 ( - 143 )
- 29 28 27 26 25 24 23 22 21 20
= (1*-29)+ (1*28)+ (0*27)+(1*26)+(1*25)+(1*24)+(0*23)+(0*22)+(0*21)+(1*20)
=-512+256+64+32+16+1
=-143→ answer
Multiplication of Signed numbers
• Case 3: Multiply the given numbers (+13) x (-11) (Negative Multiplier)
• number of bits required to represent the number +13 is 5 bits
• number of bits required to represent the number -11 is 5 bits
• Convert decimal to binary
• 13→ 1101 11→1011
• Take 2’s complement of 11→0100+1=0101
• +13 →01101(5 bits=0(sign), 1101(magnitude))
• -11→10101(5 bits=1(sign), 0101(magnitude))
• Since the multiplier is negative(-), take 2’s complement of both M(+13) and Q(-11)
and proceed as -13 and 11
• Take 2’s complement of (+13)→10010+1=10011(-13)
• Take 2’s complement of (-11)→01010+1=01011(11)
• -13 →10011(5 bits=1(sign), 0011(magnitude))
• +11→01011(5 bits=0(sign), 1011(magnitude))
Multiplication of Signed numbers
Since the multiplier is negative(-), take 2’s complement of
both M(+13) and Q(-11) and proceed as -13 and 11
1 0 0 1 1 ( - 13 )
0 1 0 1 1 ( + 11 )
1 1 1 1 1 1 0 0 1 1
1 1 1 1 1 0 0 1 1
Sign extension is
0 0 0 0 0 0 0 0 shown in red
1 1 1 0 0 1 1
0 0 0 0 0 0
1 1 0 1 1 1 0 0 0 1 ( - 143 )
- 29 28 27 26 25 24 23 22 21 20
= (1*-29)+ (1*28)+ (0*27)+(1*26)+(1*25)+(1*24)+(0*23)+(0*22)+(0*21)+(1*20)
=-512+256+64+32+16+1
=-143→ answer
Multiplication of Signed numbers
• Case 4: Multiply the given numbers (-13) x (-11)
• number of bits required to represent the number -13 is 5 bits
• number of bits required to represent the number -11 is 5 bits
• Convert decimal to binary
• 13→ 1101 11→1011
• Take 2’s complement of 13→0010+1=0011
• Take 2’s complement of 11→0100+1=0101
• -13 →10011(5 bits=1(sign), 0011(magnitude))
• -11→10101(5 bits=1(sign), 0101(magnitude))
• Since the multiplier is negative(-), take 2’s complement of both M(-13) and Q(-11) and
proceed as 13 and 11
• Take 2’s complement of (-13)→01100+1=01101(+13)
• Take 2’s complement of (-11)→01010+1=01011(+11)
• +13 →01101(5 bits=0(sign), 1101(magnitude))
• +11→01011(5 bits=0(sign), 1011(magnitude))
Multiplication of Signed numbers
0 1 1 0 1 ( + 13 )
0 1 0 1 1 ( + 11 )
0 0 0 0 0 0 1 1 0 1
0 0 0 0 0 1 1 0 1
Sign extension is
shown in red
0 0 0 0 0 0 0 0
0 0 0 1 1 0 1
0 0 0 0 0 0
0 0 1 0 0 0 1 1 1 1 ( - 143 )
- 29 28 27 26 25 24 23 22 21 20
= (0*-29)+ (0*28)+ (1*27)+(0*26)+(0*25)+(0*24)+(1*23)+(1*22)+(1*21)+(1*20)
=128+8+4+2+1 =143→ answer
Multiplication of Signed numbers
1 0 0 0 0 0 0 1 1 0 Initial 4
2 1 0 0 1 0 0 1 1 0 AA-M
1 1 0 0 1 0 0 1 1 Shift 3
3 1 1 1 0 0 1 0 0 1 Shift 2
4 0 1 0 1 0 1 0 0 1 AA+M
0 0 1 0 1 0 1 0 0 Shift 1
1 0 0 0 0 1 1 0 1 0 Initial 4
A0 0 0 0
2 1 0 0 1 1 1 0 1 0 AA-M -M 1 0 0 1
1 1 0 0 1 1 1 0 1 Shift 3 A1 0 0 1
3 0 0 1 1 1 1 1 0 1 AA+M A1 1 0 0
+M 0 1 1 1
0 0 0 1 1 1 1 1 0 Shift 2
A 10 0 1 1 Discard 1
4 1 0 1 0 1 1 1 1 0 AA-M A0 0 0 1
1 1 0 1 0 1 1 1 1 Shift 1 -M 1 0 0 1
A1 0 1 0
5 1 1 1 0 1 0 1 1 1 Shift 0
-27 26 25 24 23 22 21 20 Convert binary to decimal and the
answer is -21
Example: Multiplication of Signed numbers - Booth Algorithm
Multiply -7 x 3
Multiplicand =-7 → Binary equivalent is 1001→M
Multiplier = 3 →Binary equivalent is 0011→Q
1 0 0 0 0 0 0 1 1 0 Initial 4
A0 0 0 0
2 0 1 1 1 0 0 1 1 0 AA-M -M 0 1 1 1
0 0 1 1 1 0 0 1 1 Shift 3 A0 1 1 1
3 0 0 0 1 1 1 0 0 1 Shift 2 A0 0 0 1
+M 1 0 0 1
4 1 0 1 0 1 1 0 0 1 AA+M A1 0 1 0
1 1 0 1 0 1 1 0 0 Shift 1
5 1 1 1 0 1 0 1 1 0 Shift 0
1 0 0 0 0 1 1 0 1 0 Initial 4
A0 0 0 0
2 0 1 1 1 1 1 0 1 0 AA-M -M 0 1 1 1
0 0 1 1 1 1 1 0 1 Shift 3 A0 1 1 1
3 1 1 0 0 1 1 1 0 1 AA+M A0 0 1 1
+M 1 0 0 1
1 1 1 0 0 1 1 1 0 Shift 2
A1 1 0 0
4 0 1 0 1 0 1 1 1 0 AA-M
A1 1 1 0
0 0 1 0 1 0 1 1 1 Shift 1 -M 0 1 1 1
A0 1 0 1 Discard 1
5 0 0 0 1 0 1 0 1 1 Shift 0
-27 26 25 24 23 22 21 20 Convert binary to decimal and the
answer is 21
Multiplication of Signed numbers
– Booth Algorithm
Practice Problems
• Show the step by step multiplication process using Booth
algorithm when the following binary numbers are
multiplied. Assume 5-bit registers that hold signed
numbers. The multiplicand in both cases is +15.
• (+15) × (+13)
• (+15) × (-13)
Multiplication of Signed numbers
– Bit Pair Recoding Algorithm
• Fast Multiplication / Modified Booth Algorithm
• Bit-pair recoding halves the maximum number of summands
(versions of the multiplicand)
• - Reduces the number of Partial Products
Multiplication of Signed numbers
– Bit Pair Recoding Algorithm
Multiplier Multiplier bit Booth
Note:
on the right Multiplier Bit
Bit i+1 Bit (i)
If multiplier bit is (left bit) (Bit to modify) i-1
Implied 0 0 0 0 0×M
0 0 0 1 1 0 0 0 0 1 +1 × M
Sign extension 0 +2 -2→Bit Pair Recoding Multiplier 0 1 0 +1 × M
0
0
1 1
+2
0 1
-2
0 1 1 +2 × M
1
0
1
0
1
0
1
1
1
1
0
0
0
1
1
0
1 0
1 0 0 -2 × M
0 0 0 0 0 0
1 0 0 0 1 0 0 1 1 1 0
1 0 1 -1 × M
1 1 0 -1 × M
64+8+4+2=78
1 1 1 0× M
Multiplication of Signed numbers – Bit Pair Recoding Algorithm
Case 2: 13 x -6
0 1 1 0 1 ( + 13 )
1 1 0 1 0 ( -6 )
Multiplier Multiplier Booth
Bit i+1 Bit (i) bit on the Multiplier
• Bit- Pair Recoded Multiplier (left bit) (Bit to right Bit
Implied 0 modify) i-1
1 1 1 0 1 0 0
0 0 0 0×M
Sign extension 0 -1 -2 →Bit Pair Recoding Multiplier 0 0 1 +1 × M
0 1 1 0 1 0 1 0 +1 × M
0 -1 -2
1 1 1 1 1 0 0 1 1 0 0 1 1 +2 × M
1 1 1 1 0 0 1 1
0 0 0 0 0 0 1 0 0 -2 × M
1 1 1 0 1 1 0 0 1 0 -78
- 29 28 27 26 25 24 23 22 21 20 1 0 1 -1 × M
= (1*-29)+ (1*28)+ (1*27)+(0*26)+(1*25)+(1*24)+(0*23)+(0*22)+(1*21)+(0*20) 1 1 0 -1 × M
=-512+256+128+32+16+2
=-78→ answer 1 1 1 0× M
Multiplication of Signed numbers – Bit Pair Recoding Algorithm
Case 3: -13 x 6
1 0 0 1 1 ( - 13 )
0 0 1 1 0 (+6 )
Multiplier Multiplier Booth
Bit i+1 Bit (i) bit on the Multiplier
• Bit- Pair Recoded Multiplier (left bit) (Bit to right Bit
modify) i-1
Implied 0
0 0 0 1 1 0 0 0 0 0 0×M
Sign extension 0 +2 -2→Bit Pair Recoding Multiplier 0 0 1 +1 × M
1 0 0 1 1
0 +2 -2 0 1 0 +1 × M
0 0 0 0 0 1 1 0 1 0 0 1 1 +2 × M
1 1 1 0 0 1 1 0
0 0 0 0 0 0 1 0 0 -2 × M
-78
1 1 1 0 1 1 0 0 1 0
1 0 1 -1 × M
- 29 28 27 26 25 24 23 22 21 20
1 1 0 -1 × M
=-512+256+128+32+16+2 =-78→ answer
1 1 1 0× M
Multiplication of Signed numbers – Bit Pair Recoding Algorithm
Case 4: -13 x -6
1 0 0 1 1 ( - 13 )
1 1 0 1 0 ( -6 )
Multiplier Multiplier Booth
Bit i+1 Bit (i) bit on the Multiplier
• Bit- Pair Recoded Multiplier (left bit) (Bit to right Bit
Implied 0 modify) i-1
1 1 1 0 1 0 0
0 0 0 0×M
Sign extension 0 -1 -2 →Bit Pair Recoding Multiplier 0 0 1 +1 × M
1 0 0 1 1
0 1 0 +1 × M
0 -1 -2
0 1 1 +2 × M
0 0 0 0 0 1 1 0 1 0
0 0 0 0 1 1 0 1
1 0 0 -2 × M
0 0 0 0 0 0 1 0 1 -1 × M
0 0 0 1 0 0 1 1 1 0 64+8+4+2=78 1 1 0 -1 × M
- 29 28 27 26 25 24 23 22 21 20
1 1 1 0× M
Multiplication of Signed numbers
– Bit Pair Recoding Algorithm
Practice Problems
• Show the step by step multiplication process using Bit-pair
recoding technique when the following binary numbers are
multiplied. Assume 5-bit registers that hold signed
numbers. The multiplicand in both cases is +15.
• (+15) × (+13)
• (+15) × (-13)
Binary Division
• Long Division is a method for dividing large numbers, which
breaks the division problem into multiple steps following a
sequence.
• Restoring Method
• Non-restoring Method
Restoring Division Method
• Restoring Method
• Partial remainder is restored by adding the divisor to the negative
difference
• The restoring algorithm calculates the remainder by successively
subtracting the shifted denominator from the numerator until the remainder
is in the appropriate range. The operation in each step depends on the result
of the previous step.
• Value of Register is initially kept 0 and this is the register whose value is
restored during iteration due to which it is named Restoring.
• Comparison Method
• A and B are compared prior to the subtraction operation.
• If A ≥ B, B is subtracted from A.
• If A < B, partial remainder is shifted left and the
numbers are compared again.
Circuit Arrangement
Hardware Implementation of binary division
• It's an iterative approach that approximates the quotient and updates the
remainder in each iteration, leading to an accurate division result.
Non-restoring division algorithm, steps are described as follows:
Step 1: In this step, the corresponding value will be initialized to the registers, i.e., register A will contain value 0,
register M will contain Divisor, register Q will contain Dividend, and N is used to specify the number of bits in
dividend.
Step 2: In this step, we will check the sign bit of A.
Step 3: If this bit of register A is 1, then shift the value of AQ through left, and perform A = A + M. If this bit is 0,
then shift the value of AQ into left and perform A = A - M. That means in case of 0, the 2's complement of M is
added into register A, and the result is stored into A.
Step 4: Now, we will check the sign bit of A again.
Step 5: If this bit of register A is 1, then Q[0] will become 0. If this bit is 0, then Q[0] will become 1. Here Q[0]
indicates the least significant bit of Q.
Step 6: After that, the value of N will be decremented. Here N is used as a counter.
Step 7: If the value of N = 0, then we will go to the next step. Otherwise, we have to again go to step 2.
Step 8: We will perform A = A + M if the sign bit of register A is 1.
Step 9: This is the last step. In this step, register A contains the remainder, and register Q contains the quotient.
Non Restoring - Division
Non - Restoring Division - Steps
If the sign of A is 1,
Shift A and Q left one binary position (Left Shift),
A+M → A;
Otherwise,
Shift A and Q left one binary position (Left Shift),
A-M → A;
n cycles
If the sign of A is 1,
set q0 to 0
Otherwise,
set q0 to 1,
Repeat these steps n times
After n cycles,
If the sign of A is 1,
A+M → A; (Restore)
Perform Division by using Non-Restoring Algorithm
Dividend = 8 Divisor = 3 M=0011 Q=1000
Floating Point Representation
• Fixed-point notation (e.g., twos complement) - Very large numbers cannot be
represented, very small fractions.
• Floating - point notation
0 - positive number
1 - negative number
• Biased exponent
- An 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.
• Normalized Mantissa
- Mantissa - part of a number in scientific notation or a floating-point number
- consists of its significant digits.
- Here we have only 2 digits, i.e. O and 1.
- So a normalized mantissa is one with only one ‘1’ to the left of the decimal.
Floating Point Representation
IEEE-754 Floating Point Representation
negative
20 127 + 20 = 147
negative
0 10000101 01010100100000000000000
Floating Point Representation - Example
• Represent 85.125 in Floating Point Double Precision Format
• Steps: 3. Identify Sign bit
1. Binary Conversion sign = 0
85 = 1010101, 0.125 = 001
85.125 = 1010101.001 4. Find the Exponent with Bias Value
Biased exponent for Double precision :
2. Normalize the Mantissa Excess 1023+6 =1029
1.010101001 x 26 Exponent = 1029 = 10000000101
Normalized Mantisa = 010101001
(add 0's to complete the 52 bits) E-1023=6
E=1029
The IEEE 754 Double precision is: Exponent = 1029 = 10000000101
0 10000000101 0101010010000000000000000000000000000000000000000000
Exercise Problems
Express the number - (640.5)10 in IEEE 32 bit and 64 bit floating point format
Solution:
• IEEE 32 BIT FLOATING POINT FORMAT
MSB 8 bits 23 bits
sign Biased Mantissa/Significand
Exponent (Normalized)
Step 1: Express the given number in binary form
(640.5) = 1010000000.1* 20
Step 2: Normalize the number into the form 1.bbbbbbb
1010000000.1* 20 = 1. 0100000001* 29
Once Normalized, every number will have 1 at the leftmost bit. So IEEE notation is saying that there is no need to store
this bit. Therefore significand to be stored is 0100 0000 0100 0000 0000 000 in the allotted 23 bits
Exercise Problems
Express the number - (640.5)10 in IEEE 32 bit and 64 bit floating point format
Solution:
• IEEE 32 BIT FLOATING POINT FORMAT
MSB 8 bits 23 bits
sign Biased Mantissa/Significand
Exponent (Normalized)
Step 3: For the 8 bit biased exponent field, the bias used is
2k-1-1 = 28-1-1 = 127
Add the bias 127 to the exponent 9 and convert it into binary in order to store for 8-bit biased
exponent. 127 + 9 =136 ( 1000 1000)
1 1000 0001 000 0100 0000 0010 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
Exercise Problems
Represent -12.62510 in single precision IEEE-754 format.
Solution:
• Step #1: Convert to target base. -12.62510 = -1100.1012
• Step #2: Normalize. -1100.1012 = -1.1001012 × 23
• Step #3: Fill in bit fields. Sign is negative, so sign bit is 1.
Exponent is in excess 127 (not excess 128!), so exponent is represented as the
unsigned integer E = 3 + 127 = 130.
Leading 1 of significant is hidden, so final bit pattern is:
1 1000 0010 . 1001 0100 0000 0000 0000 000
Floating Point Arithmetic Operations
• Floating Point Operations: –
• Normal Subtraction
X = 1.01101 x 27 1.01101 x 27
Y = 1.10101 x 26 – 0.110101 x 27
0.100101 x 27
• Normal Multiplication 1.10012
X = 6.2510 = 110.012 = 1.1001 x 22
x 1.10012
Y = 12.510 = 1100.12 = 1.1001 x 23 10.011100012
• Normal Division
X = 3.7510 = 11.112 = 1.111 x 21 0.110011
Y = 95.62510 = 101 1111.1012 1.111 1.011111101
= 1.011111101 x 26
Floating Point Arithmetic Operations –
Addition/Subtraction
• Steps 0.0234 → Not normalized
0.234×10-1 --→ Normalized
• Check for 0’s in the given decimal and normalize it. (If the MSB bit is Non-zero –> Normalized)
• Choose the number with smaller Exponent.
• Align Mantissas (Shift its Mantissa right to number of positions – difference
between exponents)
• Set the exponent of result = larger exponent
• Add or Subtract Mantissas and determine the sign
• Normalize the result, if necessary
• Exponent overflow: A positive exponent exceeds the maximum possible exponent value
and this may leads to + or - in some systems
• Exponent underflow: A negative exponent is less than the minimum possible exponent
value (eg. 2-200), the number is too small to be represented and maybe reported as 0
• Significand underflow: In the process of aligning significands, the smaller number may
have a significand which is too small to be represented
• Significand overflow: The addition of two significands of the same sign may result in a
carry out from the most significant bit
Floating Point Arithmetic Operations –
Addition/Subtraction - Algorithm
Algorithm:
Floating Point Arithmetic Operations –
Addition - Example
Step 1: Normalize Mantissa Step 3: Add Mantissa
Change sign of Y
X = 1.01101 x 27
X+Y=Z 0.100101 x 27
Y = 0.110101 x 27
no no Expoenents yes Add signed Results yes
ADD X = 0? Y = 0? Round result
Equal? significands normalized?
yes yes no no
no 1.0001111 x 28
1.00101 x 26
RETURN Shift significand RETURN Significand no Decrement
right overflow? exponent
10.001111 x 27 yes
1.00101 x 26
Significand Shift significand no Exponent
Y = 0.110101 x 2no7 = 0? right underflow?
yes
1.10012
x 1.10012
10.011100012
10.01110001 x 25
=1.001110001 x 26
110
Floating Point Arithmetic Operations –
Division - Algorithm
Floating Point Arithmetic Operations –
Division - Example
X = 3.7510 = 11.112 = 1.111 x 21
Y¸X=Z
Y = 95.62510 = 101 1111.1012
= 1.011111101 x 26
E1 = 127 + 1 = 128
E2 = 127 + 6 = 133
E2 – E1 = 5
Point Division
0.110011
1.111 1.011111101
0.110011 x 25
= 1.10011 x 24
113
Non-Numeric Data Representation
There are several different variants of EBCDIC. Most of these differ in the punctuation coding.
EBCDIC character code in hexadecimal indices
Unicode
• Unicode is a character encoding standard that provides a unique number (code
point) for every character, regardless of platform, program, or language.
• Unicode supports characters from virtually all writing systems in use today.
• UTF-8, UTF-16, and UTF-32 are popular encoding schemes used to represent
Unicode characters.