0% found this document useful (0 votes)
54 views3 pages

Homework Answers Final

Uploaded by

llopezchicas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views3 pages

Homework Answers Final

Uploaded by

llopezchicas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Homework Answers

1. Convert the following numbers to binary and hexadecimal:


1.a 13₁₀:
Binary: 13₁₀ = 1101₂
Hexadecimal: 13₁₀ = D₁₆

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₁₆

2. Convert the following numbers to decimal:


2.a 10011100₂ (Binary):
Decimal: 10011100₂ = 156₁₀

2.b 9C₁₆ (Hexadecimal):


Decimal: 9C₁₆ = 156₁₀

2.c 1F₁₆ (Hexadecimal):


Decimal: 1F₁₆ = 31₁₀

2.d 0C₁₆ (Hexadecimal):


Decimal: 0C₁₆ = 12₁₀

2.e 1094₁₆ (Hexadecimal):


Decimal: 1094₁₆ = 4250₁₀

3. Convert the following numbers to their hexadecimal representation:


3.a 216₁₀:
Hexadecimal: 216₁₀ = D8₁₆

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.b -13₁₀ (Negative):


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₂

4.d -20₁₀ (Negative):


Binary: 20₁₀ = 11010010₂
2's Complement: Flip the bits and add 1 → 00101110₂

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)

5.b 13 - 8 (8 bits precision):


Binary: 13 = 01101₂, 8 = 01000₂
Result: 01101 - 01000 = 00101₂ = 5₁₀ (No overflow)

5.c 13 - 8 (8 bits precision):


Binary: 13 = 01101₂, 8 = 01000₂
Result: 01101 - 01000 = 00101₂ = 5₁₀ (No overflow)

5.d 13 + 8 (8 bits precision):


Binary: 13 = 01101₂, 8 = 01000₂
Result: 01101 + 01000 = 10101₂ = 21₁₀ (No overflow)

5.e -13 + 8 (8 bits precision):


Binary: -13 = 10011₂, 8 = 01000₂
Result: 10011 + 01000 = 11011₂ = -5₁₀ (Overflow condition)

5.f -13 - 8 (8 bits precision):


Binary: -13 = 10011₂, 8 = 01000₂
Result: 10011 - 01000 = 01011₂ = 11₁₀ (No overflow)

5.g 105 - 57 (8 bits precision):


Binary: 105 = 01101001₂, 57 = 00111001₂
Result: 01101001 - 00111001 = 00110000₂ = 48₁₀ (No overflow)

6. Perform the following multiplication operations using binary shift operations.


Check your answers:
6.a 5 * 4:
Binary: 5 = 0101₂, Left shift by 2 → 0101 << 2 = 10100₂ = 20₁₀

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')

12.b 0x69 (character 'i'):


Convert to upper case: 0x69 → 0x49 (character 'I')

12.c 0x6E (character 'n'):


Convert to upper case: 0x6E → 0x4E (character 'N')

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.

You might also like