Skip to content

Instantly share code, notes, and snippets.

@andraantariksa
Created February 24, 2020 07:11
Show Gist options
  • Save andraantariksa/8a69a0d834accd0e443c422649c5fc13 to your computer and use it in GitHub Desktop.
Save andraantariksa/8a69a0d834accd0e443c422649c5fc13 to your computer and use it in GitHub Desktop.
Answer author note:
0b prefix means binary
0o prefix means octal
0x prefix means hexadecimal
Group Assignment (3 per group)
1. Hexadecimal conversions:
a. Convert to hexadecimal: 2345.67, Round to two digits past the hexadecimal point.
b Convert your answer to binary. and then to octal
c. Devise a scheme for converting hexadecimal directly to base 4 and convert your answer to base 4
d. Convert to decimal. 0xCAD.B
2. Add, subtract, and multiply in binary
(b) 0b101110 and 0b11101
(c) 0b100100 and 0b10110
3. Subtract in binary. Place a 1 over each column from which it was necessary to borrow.
(a) 0b11001100 - 0b1001011
(b) 0b11001100 - 0b101001
4. Add the following numbers in binary using 2's complement to represent negative numbers. Use a word length of 6 bits (including sign) and indicate if an ovediow occurs.
(a) 20 + 12
(b) (-15) + (-31)
Repeat (a) and (b) using 1's complement to represent negative number.
5. Convert to octal. Convert to hexadecimal. Then convert both of your answers to decimal. and verify that they are the same
(a) 0b101010100100.101
(b) 0b101001101001.01
6. Convert the decimal number 78.9 into a number with exactly the same value represented in the following bases. The exact value requires an infinite repeating part in the fractional part of the number. Show the steps of your derivation.
(a) binary
(b) octal
(c) hexadecimal
(d) base 3
(e) base 5
7. Divide in binary:
(a) 0b11101011 / 0b101
(b) 0b110000011 / 0b1110
Check your answers by multiplying out in binary and adding the remainder.
1.
a.
2345.67 to Hexadecimal
2345
2345 9
146 2
9
929
0.67
0.67 * 16 = 10.72 10 A
0.72 * 16 = 11.52 11 B
0.52 * 16 = 8.32 8 8
0.32 * 16 = 5.12 5 5
0.12 * 16 = 1.92 1 1
AB851
0x929.AB851
b. NOT COMPLETED
0x929.AB851 to Decimal
929
9 1001
2 0010
9 1001
100100101001
c. NOT COMPLETED
d.
0xCAD.B to decimal
D 13*16^0 = 13
A 10*16^1 = 160
C 12*16^2 = 3072
13 + 160 + 3072 = 3245
B 11*16^-1 = 0.6875
0.6875
3245 + 0.6875 = 3245.6875
2.
Add, subtract, multiply
a.
101110 and 11101
111 <- carry
101110
011101
======= +
1001011
02 02 <- borrow
101110
011101
====== -
010001
1 0 1 1 1 0
0 1 1 1 0 1
=========== *
1 1 2 2 2 1 1 <- carry
1 0 1 1 1 0
0 0 0 0 0 0
1 0 1 1 1 0
1 0 1 1 1 0
1 0 1 1 1 0
0 0 0 0 0 0
===================== +
1 0 1 0 0 1 1 0 1 1 0
b.
100100 and 10110
1 <- carry
100100
010110
====== +
111010
0112
02 <- borrow
100100
010110
====== -
001110
1 0 0 1 0 0
0 1 0 1 1 0
=========== *
1 1 0 <- carry
0 0 0 0 0 0
1 0 0 1 0 0
1 0 0 1 0 0
0 0 0 0 0 0
1 0 0 1 0 0
0 0 0 0 0 0
===================== +
0 1 1 0 0 0 1 1 0 0 0
3.
a.
012 <- borrow
11001100
01001011
======== -
10000001
b.
02 012 <- borrow
11001100
00101001
======== -
10100011
4.
a.
20 + 12
1s complement
20 0b10100
12 0b1100
With 6 bit + sign
20 0b010100
12 0b001100
1 1 1 <- carry
0 1 0 1 0 0
0 0 1 1 0 0
=========== +
1 0 0 0 0 0
0b100000 = 0b011111 = -31
^ ^
| minus | 31
Overflow occur because the carry attempt to change the sign
2s complement
20 0b10100
12 0b1100
With 6 bit + sign
20 0b010100
12 0b001100
1 1 1 <- carry 1 1 1 1 1 <- carry
0 1 0 1 0 0 0 1 1 1 1 1
0 0 1 1 0 0 0 0 0 0 0 1
=========== + =========== +
1 0 0 0 0 0 1 0 0 0 0 0
Overflow occur because the carry attempt to change the sign
0b100000 = 0b011111 + 0b1 = 0b100000 = -32
^ ^
| minus | 32
b.
(-15) + (-31)
1s complement
31 0b11111
15 0b1111
With 6 bit + sign
31 0b111111
15 0b101111
1 1 1 1 1 <- carry
1 1 1 1 1 1
1 0 1 1 1 1
=========== +
1 1 0 1 1 1 0
Overflow occur because the carry attempt to change the sign
0b1101110 = 0b0010001 = -17
^ ^
| minus | 17
2s complement
31 0b11111
15 0b1111
With 6 bit + sign
31 0b111111
15 0b101111
1 1 1 1 1 <- carry
1 1 1 1 1 1
1 0 1 1 1 1
=========== +
1 1 0 1 1 1 0
^
| clamp the bits
Overflow occur because the carry attempt to change the sign
0b1101110 = 0b0010001 + 0b1 = 0b0010010 = 18
^ ^
| minus | 18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment