Classwork 16: Converting to Binary

Wednesday, May 09, 2012     


[Previous Classwork] [Next Classwork]


Complete the following:

  1. Create a file named cw16.c
  2. You are to write a program that will accomplish the following:
    1. Prompt the user to either convert decimal to binary or binary to decimal.
    2. Read in either a decimal or binary number as a string.
    3. Convert the number to the other format.
    4. Print your solution.
    5. Repeat step 1 until the user enters "quit"
  3. For Extra credit, add functionality that will allow a user to convert decimal to hexadecimal and vice versa.
  4. For Extra Extra credit, add functionality that will allow a user to convert between octal and decimal. You will have to look this one up online.
  5. For Extra Extra Extra credit, add functionality that will act as follows:

      D - Decimal
    B - Binary
    H - Hexadecimal
    O - Octal
    Please select the input format: D
    Please enter your Decimal number: 64
    Decimal Binary Hexadecimal Octal
    --------------------------------------------
    64 0b100000 0x40 0o100

  6. Once you are done, use submit to submit one file,

    linux3[26]% submit cs104 cw16 cw16.c
    

  7. After submitting your file, you can verify your file was submitted by using the submitls command
  8. MAKE SURE YOU LOGOUT AFTER SUBMITTING THE ASSIGNMENT AND BEFORE LEAVING CLASS!