1.2 Number Representation v12.0
1.2 Number Representation v12.0
Representation in
Computers
Why computers use binary
system?
Most of data storing,
transferring, and processing in
computers happens with
digital electronics.
Digital electronics use the
binary system (ON/OFF) or
two different current levels.
For example, 5 volts and 0
volts.
A signal with a series of ON/OFF pulses is equal to a binary
number.
This requires the least amount of electronic circuitry systems.
Page 2
Why computers use binary
system?
If decimal system is used, then 10 different current levels
are required to be used. This requires more circuitry and
additional (10) voltage levels.
However, least amount of necessary circuitry, will results in
the least amount of space, energy consumption, and cost.
Further, differentiating between 10 different voltage levels
could be difficult than 2, because of possible fluctuations in
current.
Moreover, even if binary circuits are combined to represent
decimal, then there will be minimum of 16 levels (2 4 – as
23 is not sufficient), wasting values from 10 to 15.
Page 3
Number System Conversions
Binary Vs Decimal
Hexa-Decimal Vs Decimal
Page 4
What is a bit ?
A bit is the most basic unit of information in computing.
1
0
Page 5
Representation of Information
"Word size“ or “Word Length” refers to the multiple
number of bits processed by a computer's CPU in one go
(these days, typically 32 bits or 64 bits).
8 7 6 5 4 3 2 1
An 8-bit word
Page 6
Integers
Integer Number Representations
in the computer
Integer Numbers
Two’s Compliment
Page 8
Un-Signed Numbers
Unsigned numbers don’t have any sign, these can
contain only magnitude of the number.
Computers do not allocate space to record the sign of
such numbers.
So, generally, representation of unsigned binary
numbers are all considered positive numbers only.
Page 9
Un-Signed Number representation
14110 = 100011012
8 7 6 5 4 3 2 1
1 0 0 0 1 1 0 1 = 141
Page 10
Un-Signed Number example
10210 = 11001102
8 7 6 5 4 3 2 1
0 1 1 0 0 1 1 0 = 102
Page 11
Signed Numbers
In real life we need to be able represent both positive
numbers and negative numbers (signed) numbers
like: -12, -45, +78.
A signed number MUST have a sign (+ or -). A
method is needed to represent the sign as part of the
binary representation.
The signed number representation methods are:
Sign and Magnitude representation
Two’s-complement representation
Page 12
Sign and Magnitude
Representation
In sign and magnitude (S&M) representation, the leftmost bit of
the word represents the sign of the value:
0 for positive,
1 for negative;
Page 13
Sign and Magnitude
Representation
Example 1
Find the S&M representation of -6 10 (in 8-bit word length)
Answers
8-bit 6-bit
31 = 0 0 0 1 1 1 1 1 0 1 1 1 1 1
-11 = 1 0 0 0 1 0 1 1 1 0 1 0 1 1
27 = 0 0 0 1 1 0 1 1 0 1 1 0 1 1
-100 = 1 1 1 0 0 1 0 0 1 0 0 1 0 0
Page 17
Sign and Magnitude
Representation
Exercise
Find the decimal value of following S&M representations
1. 1 1 1 1 1 1 1 1
2. 1 0 0 0 0 0 0 1
3. 0 1 0 1 0 1 0 1
4. 0 0 1 0 1 0 1 0
Answers
1. -127
2. -1
3. 85
4. 42
Page 18
Sign and Magnitude
Representation
Add following values in S&M (using 4 bit word length):
+2 +2
-4 + -2 +
Page 19
Sign and Magnitude
Representation
Disadvantages
+2 0010 +2 0010
-4 1100 -2 1010
--- ------ --- -----
-6 1110 -4 1100
The result is -6, which is not what we expect The result of -4, which again is not what we
expect
Page 20
Two’s Complement
Representation
Two’s compliment is another method used to represent binary
numbers by most modern computers.
Page 21
Two’s Complement
Representation
In-order to represent a negative decimal value using Two’s
complement:
Page 22
Two’s Compliment Representation
Represent -7 in 8bit word size.
Step 1: Assume -7 as +7, convert to binary and place it in 8bit word.
Page 24
Two’s Complement
Representation
Example 1 (contd….)
Page 26
Two’s Complement
Representation
Example 3
Find the 8-bit two’s complement representation of -80
(complemented) 10101111
(add one) + 1
10110000
Page 28
Decimal to 2’s compliment conversion
Exercise
Convert following decimal value into their 2’s compliment values
using 8-bit and 10-bit word sizes:
a) -123
b) 100
c) -13
d) 77
Page 30
Two’s Complement to Decimal
Example 1
Find the decimal equivalent of the 8-bit 2’s complement
value 111011002
Determine if number is positive or negative:
Page 32
Two’s Complement to Decimal
Example 2
Find the decimal equivalent of the 8-bit 2’s
complement value 010010002
Exercise
Convert following 2’s compliment values to equivalent decimal value:
a) 01011010
b) 10100101
c) 11111010
d) 00110111
Answers
a) 90
b) -91
c) -6
d) 55
Page 34
2’s compliments Additions
Page 35
Exercise - 2’s compliments addition
Exercise
1. 44 + 45
2. -75 + 59
3. (-19) + (-7)
4. 10 + (-3)
5. 1 + (-1)
Page 36
2’s compliments Addition
Answers
Page 38
Exercise - 2’s compliments addition
Exercise
1. 104 + 45
2. 127 + 1
3. (-103) + (-69)
Page 39
2’s compliments addition overflow
errors
The rules for detecting overflow in a two's complement sum are simple:
1.If the sum of two positive numbers yields a negative result, the sum has
overflowed.
2.If the sum of two negative numbers yields a positive result, the sum has
overflowed. Page 40
Two’s Complement Benefits
Page 41
Floating Point
Numbers
Floating Point Numbers
In real life we also need to be able represent
numbers with fractional parts (like: -12.5 &
45.39).
When dealing with numbers with fractional
parts, computers use a technique, known as
floating point representation (FP).
In computers, Floating Point numbers are
represented using IEEE 32-bit floating point
format.
Page 43
Floating Point Numbers
Page 44
How to convert Binary Floating Point
Numbers to Decimal
Page 45
How to convert Binary Floating Point
Numbers to Decimal
Answers
• 11.1 = 3.5
• -101.101 = -5.625
• 111.1001 = 7.5625
Page 46
How to convert Decimal Floating
Point Numbers to Binary
Page 47
How to convert Decimal Floating
Point Numbers to Binary
Exercise
Convert following decimal fraction values to binary
• 12.875
• -29.375
• 10.1
Answers
Same problem exists
• 12.875 = 1100.111 with 10.2, 10.3, … etc
• -29.375 = -11101.011
• 10.1 = 1010.000110011001100110………….
Page 48
Problem storing binary form
Is there a way to store the radix point????
Page 49
IEEE Floating Point Representation
IEEE committee came up with a way to store binary floating
point numbers – known as IEEE-32 which also could indicate
the radix point.
Floating point numbers can be stored into 32-bits, by dividing
the bits into three parts:
sign exponent mantissa
1 2 910 32
Page 50
Normalization of floating point
number
Binary floating point number should be normalized in such
a way that radix point falls to the right of the leftmost bit 1.
Mantissa Exponent
Page 53
Note on Mantissa
Page 54
Steps in IEEE – 32 Representation of
a decimal value
1. Convert the Decimal floating point number
to a binary floating point number
2. Normalize the binary floating point
number
3. Convert the exponent in to a biased
exponent and convert it to 8 bit binary
value
4. Represent in IEEE-32 format
Page 55
Decimal Floating Point to
IEEE standard Conversion
Example 1
Find the IEEE FP representation of 40.15625
Step 1: Compute the binary equivalent of the whole part and the
fractional part. (i.e. convert 40 and .15625 to their binary equivalents)
101000.00101 = 1.0100000101 x 25
Page 56
Decimal Floating Point to
IEEE standard Conversion
Example 1 (contd…)
Step 3. Convert the exponent to a biased exponent
127 + 5 = 132
13210 = 100001002
Example 2
Find the IEEE FP representation of –24.75
Step 1. Compute the binary equivalent of the whole part and the
fractional part.
-11000.11 = -1.100011 x 24
Page 58
Decimal Floating Point to
IEEE standard Conversion
Example 2 (contd…)
Answers
1.
2.
Page 60
S F E
S is the sign bit. Like integer formats, 1 indicates a negative number while
zero indicates positive.
F is the fractional part of the mantissa. The non-fractional part is not stored,
and assumed to be always 1, so the actual mantissa is “1.F” . This method
provides an additionall room of one bit to store the precision of the value.
While (F) mantissa provides the precision of the number, the scale or
extent of the magnitude is provided by the (E) exponent.
Page 61
Conversation from IEEE standard
to Decimal Floating Point
Page 62
Steps in IEEE- 32 standard to
Decimal Floating Point Conversion
Example
Sign Exponent Mantissa
1) 1 01111101 01000000..0
2) 0 10000011 10011000..0
Page 64
IEEE standard to Decimal
Floating Point Conversion.
Example 1
Convert the following 32-bit binary number to its decimal floating point
equivalent:
Example 1 (contd…)
Step 2: Write Normalized number in the form:
1.MANTISSA x 2Exponent
For our number:
-1. 01 x 2 –2
Example 1 (contd…)
Step 4: Convert binary number to the decimal floating point
equivalent.
= -0.312510
Page 67
IEEE standard to Decimal
Floating Point Conversion.
Example 2
Convert the following 32 bit binary number to its decimal floating point
equivalent:
Example 2 (contd…)
Step 2: Write Normalized number in the form:
1.MANTISSA x 2Exponent
For our number:
1.10011 x 2 4
Example 2 (contd…)
Step 4: Convert binary number to the decimal floating point
equivalent.
= 25.510
Page 70
IEEE- 32 standard to Decimal
Floating Point Conversion
Exercise
Sign Exponent Mantissa
1) 0 01110111 00000000000..0
1 10000011 001101100100.0
2)
Answers
1. 0.00390625
2. -19.390625
Page 71
Steps in Floating Point number
addition
ADD the normalized values [ 1.000 × 2-1 ] + [ -1.110 × 2-2 ]
1. Ensure all values that required to be added are normalized. If not, normalize the values.
2. In order to perform addition, the exponents of the two values should be equal.
a. If not, lower exponent should be adjusted, and made equal to the higher exponent.
(therefore, adjust the second value such that its exponent matches with the exponent of the first
value.)
-1.110 × 2-2 = -0.1110 × 2-1
3. Add the two values:
[1.000 × 2-1] + [-0.1110 × 2-1] = 0.001 × 2-1
4. Re- Normalize the result (so that final value could be stored in IEEE format)
0.001 × 2-1 = 1.000 × 2-4
5. Round –off the result:
If the mantissa does not fit in to the space reserved for it (23 bits), mantissa has to be
rounded off. (this could occur, especially if the two values are multiplied).
Page 72
Floating Point number addition
Page 74
Floating Point number limitations
Page 75
Floating Point number limitations
(contd…)
2. ROUNDING OFF – ERRORS
I. PRECISION LIMITATION
Floating point representation cannot store very large
numbers or very small numbers which exceed more
than 23 positions (since that is the max for mantissa
value)
II. A very significant difference between integer and
floating point calculations is that floating point
calculations do not yield accurate results.
Multiplying two floating point numbers X and Y can
yield an error. This error is due to the way in which
the mantissa is extended during operations (that is
mantissa of the result may go beyond 23 bits).
Page 76
Integer vs Floating
Point Numbers
About Integers….
Page 78
About Floating Point numbers…..