Difference between revisions of "Binary Converters Assignment"
From WLCS
(Created page with "== Objectives == * You will write Python programs to convert the following: ** Binary <-> Decimal ** Binary <-> Hexadecimal == Directions == # Create a Python program named '''b...") |
|||
Line 10: | Line 10: | ||
##* 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 | ||
##* Return the decimal number (int) of the binary string | ##* Return the decimal number (int) of the binary string | ||
+ | <!-- | ||
## '''dec2bin(dNum)''' | ## '''dec2bin(dNum)''' | ||
##* This function takes a number '''dNum''' as a parameter, which is an integer | ##* This function takes a number '''dNum''' as a parameter, which is an integer | ||
##* Return the binary string that corresponds to the integer | ##* Return the binary string that corresponds to the integer | ||
+ | --> | ||
## '''bin2hex(bStr)''' | ## '''bin2hex(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 |
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 4 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