Homework Answers Final
Homework Answers Final
1.b 15₁₀:
Binary: 15₁₀ = 1111₂
Hexadecimal: 15₁₀ = F₁₆
1.c 25₁₀:
Binary: 25₁₀ = 11001₂
Hexadecimal: 25₁₀ = 19₁₆
1.d 157₁₀:
Binary: 157₁₀ = 10011101₂
Hexadecimal: 157₁₀ = 9D₁₆
1.e 325₁₀:
Binary: 325₁₀ = 101000101₂
Hexadecimal: 325₁₀ = 145₁₆
1.f 1096₁₀:
Binary: 1096₁₀ = 10001001000₂
Hexadecimal: 1096₁₀ = 448₁₆
3.b 224₁₀:
Hexadecimal: 224₁₀ = E0₁₆
3.c 229₁₀:
Hexadecimal: 229₁₀ = E5₁₆
3.d 234₁₀:
Hexadecimal: 234₁₀ = EA₁₆
3.e 231₁₀:
Hexadecimal: 231₁₀ = E7₁₆
4. Provide the 2's complement form for the following numbers:
4.a 13₁₀:
Binary: 13₁₀ = 01101₂
2's Complement: Flip the bits and add 1 → 10011₂
4.c 15₁₀:
Binary: 15₁₀ = 10011100₂
2's Complement: Flip the bits and add 1 → 01100100₂
5. Perform the following calculations using 2's complement arithmetic. Show whether
there is an overflow condition or not:
5.a 13 + 8 (8 bits precision):
Binary: 13 = 01101₂, 8 = 01000₂
Result: 01101 + 01000 = 10101₂ = 21₁₀ (No overflow)
6.b 13 * 12:
Binary: 13 = 1101₂, Left shift by 3, add original → 1101 << 3 = 11000₂ = 104₁₀
6.c 7 * 8:
Binary: 7 = 0111₂, Left shift by 3 → 0111 << 3 = 11000₂ = 56₁₀
6.d 15 * 5:
Binary: 15 = 1111₂, Left shift by 2 → 1111 << 2 = 111100₂ = 60₁₀
7. What is the hex representation of the following numbers (note that they are
strings)?
7.a '52':
Hexadecimal: 52₁₀ = 34₁₆
7.b '-127':
Hexadecimal: -127₁₀ = 81₁₆
8. Perform the following multiplication and division operations using only bit
shifts:
8.a 12/8:
Binary: 12 = 1100₂, Right shift by 3 → 1100 >> 3 = 0011₂ = 3₁₀
8.b 8 * 16:
Binary: 8 = 1000₂, Left shift by 4 → 1000 << 4 = 100000₂ = 128₁₀
8.c 12 * 10:
Binary: 12 = 1100₂, Left shift by 3 → 1100 << 3 = 110000₂ = 96₁₀
8.d 7 * 15:
Binary: 7 = 0111₂, Left shift by 4 → 0111 << 4 = 111100₂ = 121₁₀
12. Convert the following ASCII characters from lower case to upper case (do not
refer to the ASCII table):
12.a 0x62 (character 'b'):
Convert to upper case: 0x62 → 0x42 (character 'B')
13. Write the functions `toUpper` and `toLower` in a high-level language of your
choice.
```python
def toUpper(input_string):
result = ""
for char in input_string:
if 'a' <= char <= 'z':
result += chr(ord(char) - 32)
else:
result += char
return result
def toLower(input_string):
result = ""
for char in input_string:
if 'A' <= char <= 'Z':
result += chr(ord(char) + 32)
else:
result += char
return result
```
These functions convert all the letters in a string to either uppercase or
lowercase.