CPSC120A
Fundamentals of Computer Science I

Lab 20

Binary Integer

Use the command line to create a new directory called lab20 in your labs directory. Make sure all of the files that you create for this activity are in that directory.

Binary Integer

In Emacs, create a text file called binary_int.txt. In that file answer the following questions on binary numbers.

  1. What is the binary number 100 in decimal?

  2. What is the the binary number 10101010 in decimal?

  3. What is the decimal number 5 in binary?

  4. What is the decimal number 72 in binary?

  5. What is the largest number, in binary, that can be represented with 8 bits?

  6. What is the largest number, in decimal, that can be represented with 8 bits?

  7. What is the largest number that the Python programming language can represent?

Base Conversion

Create a Python function called to_binary(integer) in a file called binary_int.py. The function should have one parameter, integer, that is a non-negative integer. The function should return a string that is the binary encoding of the specified integer. Be sure to include test cases for your function.

Submission

Please show your source code and run your programs for the instructor or lab assistant. Only programs that have perfect style and flawless functionality will be accepted as complete.