Binary Converters Assignment
From WLCS
Objectives
- You will write Python programs to convert the following:
- Binary <-> Decimal
- Binary <-> Hexadecimal
Directions
- Create a Python program named binaryConverters.py
- Create the following 3 functions:
- 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
- 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
- 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
- bin2dec(bStr)
Testing
- Test out each of your functions on your own
- Mr. Bui will give you his test cases next week