Binary Converters Assignment

From WLCS
Revision as of 14:40, 7 June 2013 by Admin (talk | contribs) (Created page with "== Objectives == * You will write Python programs to convert the following: ** Binary <-> Decimal ** Binary <-> Hexadecimal == Directions == # Create a Python program named '''b...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 4 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. dec2bin(dNum)
      • This function takes a number dNum as a parameter, which is an integer
      • Return the binary string that corresponds to the integer
    3. 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
    4. 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