Binary Converters Assignment

From WLCS

Objectives

  • You will write Python programs to convert the following:
    • Binary <-> Decimal
    • Binary <-> Hexadecimal

Directions

  1. Create a Python program named binaryConverters.py
  2. Create the following 3 functions:
    1. bin2dec(bStr)
      • This function takes a string bStr as a parameter, and the string contains 1s and 0s that represent a binary number
      • Return the decimal number (int) of the binary string
    2. bin2hex(bStr)
      • This function takes a string bStr as a parameter, and the string contains 1s and 0s that represent a binary number
      • Return the hexadecimal string that represents the binary string
    3. hex2bin(hexStr)
      • This function takes a string hexStr as a parameter, and the string contains hexadecimal (0-9, a-f, A-F)
      • Return the binary string that represents the hexadecimal

Testing

  1. Test out each of your functions on your own
  2. Mr. Bui will give you his test cases next week