Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
SleekPanther committed Mar 3, 2017
1 parent edc809b commit 9c615ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Binary Hexadecimal Conversion
Convert hex to binary and binary to hex
Convert hex to binary and binary to hex by slicing inputs & outputs into 4-bit nibbles

##Notes
- Choose to which direction to convert
Expand All @@ -8,3 +8,12 @@ Convert hex to binary and binary to hex
##Limitations
- 32-bit binary input
Not really an issue, since you can simply change `MAX_BITS_ALLOWED` to allow infinite sequences of 0's and 1's

##Code Details
- Uses 2 dictionaries of 4-bit nibbles to convert both ways
- Robust error handling checks:
- Binay input is <= 32 bits
- Empty string input is correctly returns 0000 binary or 0 hex
- Hex is converted to uppercase to avoid duplicate dictionary keys for lowercase
- Binary input is validated to make sure it is only 0's and 1's
- Hex input catches KeyErrors if the input is not a value 0-9 or A-F
3 changes: 3 additions & 0 deletions binary-hexadecimal-conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
'D':'1101',
'E':'1110',
'F':'1111' }

MAX_BITS_ALLOWED = 32 #used to limit user input
NIBBLE_SIZE = 4 #half a byte. (4 digits long of 1's and 0's)


def showWelcomeScreen():
userChoice=input('\n\tHex & Binary Converter \nEnter 1 to convert unsigned binary to hexadecimal \nEnter 2 to convert hexadecimal to unsigned binary \nQuit (any other character) \nYour choice: ')
userChoice=userChoice.lstrip(' ') #remove leading spaces
Expand Down

0 comments on commit 9c615ac

Please sign in to comment.