Exercise 2: (52)10 =
_____________________________________________________________________.
Exercise 3: (100)10 =
____________________________________________________________________.
In decimal system we have 10 symbols namely 0, 1, 2, 3, ,9 to represent a
number. In the same manner a binary system will have 2 symbols namely 0 and 1.
If we look at example 2, then we can represent the number 39 in decimal
as 100111 in binary. Note that they are nothing but the coefficients of the power
of 2 in the expansion of 39. The left most digit is the coefficient of highest power i.e
2^5 and rightmost digit is coefficient of 2^0 terms. They are respectively called as
Most Significant Bit and Least Significant Bit.
Lets convert 100 and 255 to binary using method 2. Make sure you use 8
bits to represent them.
Exercise 10: (100)10 = (___________ ___________________________)2.
Exercise 11: (255)10 = (___________ ___________________________)2.
Exercise 12:
Represent the following unsigned decimal numbers in binary using (a) minimum
number of bits, and (b) using 16-bit representation.
a) 102 : ____________________________________________(min bits)
________________________________________________(16 bits)
b) 65000 :__________________________________________ (min bits)
________________________________________________(16 bits)
How to convert a number given in binary to decimal? The answer lies in its
expansion. So for example 10110 in binary is 1x2^4 + 0 x2^3 + 1 x 2^2 + 1 x 2^1
+ 0 ^ 2^0 = 16 + 4 + 2 = 22 in decimal. You should try out all the binary
representations done above back to decimal to verify your answers.
2.
Add one.
1
0 0 0 1 (1)
0 0 1 1 (3)
00
1
0 0 0 1 (1)
0 0 1 1 (3)
100
0
0 0 0 1 (1)
0 0 1 1 (3)
0100
So lets say we want to subtract 7 -2. This is same as adding 7 + (-2). So lets see
what happens
Example 7:
0111 (7)
+1110 (-2)
10101
Ignore the last carry out i.e. 1 in this case. So the result is 0101 = 5 = 7 2.
Exercise 17: Compute the following
0 0 1 0 (2)
1 1 1 0 (-2)
+ 0 1 0 1 (5)
+ 1 1 1 0 (-2)
Exercise 18: The following binary numbers are 4-bit 2's complement binary
numbers. Which of the following operations generate overflow?
1100
+0 0 1 1
Y/N
1100
+0100
Y/N
0111
+0001
Y/N
0111
+1001
Y/N
For overflow detection, other than the technique said in recorded lectures, the
following can also be used:
Suppose A and B are two numbers and A+B = C. Checking the sign of A, B, and C
can tell whether overflow has occurred or not. If the sign of A and B is same (either
positive or negative), overflow will occur if the sign of C is different from A and B.
This is because if two positive numbers are added together, result can never be
negative and vice versa. Check this out in Q6 above.
Exercise 19: What if the sign of A and B is different?
arithmetic. This is done by appending digits to the most significant side of the
number, following a procedure dependent on the particular signed number
representation used.
Here one needs to be careful, when sign extending a negative number represented
using sign magnitude representation. Lets say 1000 1001 is the sign magnitude
representation of -9 using 8 bits. Then in order to sign extend it to 16 bits you will
have to write 1000 0000 0000 1001. In this manner the value as well as the sign in
sign magnitude representation will be preserved.
in
in
in
Practice some of the arithmetic problems using the different representations you
have learnt till now.
Exercise 24: Add A and B (using 2's complement representation). Check if
there is an overflow
a) A
=
-60,
B
=
-70
____________________________________________________Overflow : Y/N
b) A397
+
A35D
_______________________________________________________________
Section
5:
(Fractions)
Representing
Floating
point
Numbers
3.
For the fractional part, multiply the fractional part by 2 repeatedly, and collect
the integral part in the same order.
Integer part is 0.
0.25 x 2 = 0.5
0.5 x 2 = 1.00
Integer part is 0.
Integer part is 1.
Integer part is 0
15.625
_________________________________________________________________________________________
___
0.0625
=_______________________________________________________________________________________
_____
50.9375
_________________________________________________________________________________________
___
Obviously we would like to learn, given a fractional number in binary how to convert it
into decimal.
So the method to do it is
1. Separate the integral and the fractional parts.
2.
3.
=
_________________________________________________________________________________________
101.101
___
0.0001
=_______________________________________________________________________________________
_____
101010.1111
_________________________________________________________________________________________
__
0.010456 = ____________________________________________________________________________
11101.0010 = _________________________________________________________________________
0.000010101
_________________________________________________________________________
Over the years, a standard evolved for representing a floating point number called IEEE
754 standard. It has two formats called single precision and double precision. Single
precision format uses 32 bits whereas Double precision uses 64 bits.
In 32-bit single-precision floating-point representation:
The most significant bit is the sign bit (S), with 0 for positive numbers and 1 for
negative numbers.
The following 8 bits represent exponent (E).
The remaining 23 bits represents fraction (F).
1101
0100
0000
0000
0000
0000
0000:
0101
0101
0110
0000
0000
________________________________________________
0000
0000
0000:
1100
0000
0000
0000:
________________________________________________
0001
1111
0000
0000
________________________________________________
a)
55
23
64
_______________________________________________________________________________
b) 64000 _________________________________________________________________________
c) 128_____________________________________________________________________________
d) 0.0625 _________________________________________________________________________