Program Development

There are several full length programs in the book. I would like you to copy these pieces of code and get them to run. Your code must have the following template:

def main():
  # the body of the program

Each program will be in a file by itself with .py extension. You must make sure that it runs as shown in the book. These programs do NOT have to be turned in. However, you are likely to see variations of these programs in the quizzes.

Number Conversions

  1. Convert the following numbers in decimal to 8-bit 2's complement binary: 28, -39
  2. Write the binary equivalent of all numbers from 0 to 15 in 4-bit binary.
  3. These are 8-bit 2's complement binary. What decimal numbers do they represent?
  4. Convert the following numbers to unsigned binary, octal, and hexadecimal: 25, 32, 67, 96.
  5. Convert these numbers in octal to binary, decimal, and hexadecimal: 672, 215.
  6. Convert these hexadecimal numbers into binary, octal, and decimal: 2A5, D0C.
  7. The hexadecimal number B4 is a 2's complement number in 8-bit binary. Convert it to decimal.
  8. Add 3D and F5 and express the answer in octal.
  9. Add 517 in octal to 3A in hexadecimal and express the answer in decimal. [Hint convert both numbers to binary and add.]
  10. Add the following 2's complement 8-bit numbers: 1011 1001 and 1110 0110. Ignore the overflow bit. Express the answer in decimal.