Skip to content

Commit 9c615ac

Browse files
committed
Update README.md
1 parent edc809b commit 9c615ac

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Binary Hexadecimal Conversion
2-
Convert hex to binary and binary to hex
2+
Convert hex to binary and binary to hex by slicing inputs & outputs into 4-bit nibbles
33

44
##Notes
55
- Choose to which direction to convert
@@ -8,3 +8,12 @@ Convert hex to binary and binary to hex
88
##Limitations
99
- 32-bit binary input
1010
Not really an issue, since you can simply change `MAX_BITS_ALLOWED` to allow infinite sequences of 0's and 1's
11+
12+
##Code Details
13+
- Uses 2 dictionaries of 4-bit nibbles to convert both ways
14+
- Robust error handling checks:
15+
- Binay input is <= 32 bits
16+
- Empty string input is correctly returns 0000 binary or 0 hex
17+
- Hex is converted to uppercase to avoid duplicate dictionary keys for lowercase
18+
- Binary input is validated to make sure it is only 0's and 1's
19+
- Hex input catches KeyErrors if the input is not a value 0-9 or A-F

binary-hexadecimal-conversion.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@
3636
'D':'1101',
3737
'E':'1110',
3838
'F':'1111' }
39+
3940
MAX_BITS_ALLOWED = 32 #used to limit user input
4041
NIBBLE_SIZE = 4 #half a byte. (4 digits long of 1's and 0's)
42+
43+
4144
def showWelcomeScreen():
4245
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: ')
4346
userChoice=userChoice.lstrip(' ') #remove leading spaces

0 commit comments

Comments
 (0)