Difference between revisions of "Binary Converters Assignment"
From WLCS
Line 6: | Line 6: | ||
== Directions == | == Directions == | ||
# Create a Python program named '''binaryConverters.py''' | # Create a Python program named '''binaryConverters.py''' | ||
− | # Create the following | + | # Create the following 3 functions: |
## '''bin2dec(bStr)''' | ## '''bin2dec(bStr)''' | ||
##* This function takes a string '''bStr''' as a parameter, and the string contains '''1s''' and '''0s''' that represent a binary number | ##* This function takes a string '''bStr''' as a parameter, and the string contains '''1s''' and '''0s''' that represent a binary number |
Latest revision as of 13:39, 11 June 2013
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