Practice Questions for “representing things with binary quantities”:
1. Decimal from/to binary:
a. Convert the following decimal numbers to 8-bit binary:
67
Successively divide with 2:
67/2 = 33 rem 1
33 / 2 = 16 rem 1
16 / 2 = 8 rem 0
8 / 2 = 4 rem 0
4 / 2 = 0 rem 0
2 / 2 = 1 rem 0
1 / 2 = 0 rem 1
So, the result is 01000011. The underlined 0 is there because
we are using the full 8-bits. Our calculations show that 67 can be represented
with just 7-bits.
156
= 10011100
-36
= 11011100
Double-check your results by converting back to decimal.
b. Convert the following binary numbers to decimals assuming the numbers are unsigned:
0010
1101 = 45
1001
1001 = -102
c. Repeat for the preceding two numbers assuming that the numbers are signed in 2’s complement
2. Hexadecimal
a.
Convert 0xdabc1fe2 to binary 1101 1010 1011 1100 0001
1111 1110 0010
b.
Write 001 0100 1101 in hexadecimal 0x14d. Note that the
binary number has 11 digits. We add a zero to make it 12 bits and then convert
to hexadecimal (0001 0100 1101)
c.
Convert -2 (in decimal) into a 16-bit binary number in 2’s complement
and then write the 2’s complement’s representation in hexadecimal.
1111 1111 1111
1110
0xFFFE
3. Floating point
a. Convert 128.128 into the 32-bit IEEE floating point representation.
01000011000000000010000011000101
I haven’t double-checked
this tool, but try it out if you need to practice:
http://www.h-schmidt.net/FloatApplet/IEEE754.html
b. Write a C program that demonstrates that not all decimal numbers can be exactly represented using the 32-bit IEEE floating point representation. Use 37.64 as your decimal number. Store it in a floating point number and then print it out.
#include <stdio.h>
main()
{
float
f=32.64;
printf ("%f", f);
}
4. Arbitrary Numerical Representation
Design
a digital circuit that adds two two-bit numbers and produces their two-bit sum
(the adder does addition modulo 3) assuming the following representation of
numbers:
0
-> 00
1
-> 10
2
-> 11
3
-> 01
Provide the truth table for this circuit. It accepts two 2-bit inputs and produces one 2-bit output.
Let a1 a0 and b1 b0 the two inputs and x1 x0 the output.
a1a0 b1b0 | x1x0
0 0 0 0 0 0
0 0 0 1 0 1
0 0 1 0 1 0
0 0 1 1
1 1
-------------------
0 1 0 0 0
1
0 1 0 1 1 1 ( 3 + 3 = 6 MOD 4 = 2)
0 1 1 0 0 0 ( 3 + 1 = 4 MOD 4 = 0)
0 1 1 1 1
0 ( 3 + 2 = 5 MOD 4 = 1)
--------------------
1 0 0 0
1 0
1 0 0 1 0 0
1 0 1 0 1
1
1 0 1 1 0 1
-------------------
1 1 0 0
1 1
1 1 0 1 1 0
1 1 1 0 0
1
1 1 1 1 0 0