File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 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
1010Not 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
Original file line number Diff line number Diff line change 3636 'D' :'1101' ,
3737 'E' :'1110' ,
3838 'F' :'1111' }
39+
3940MAX_BITS_ALLOWED = 32 #used to limit user input
4041NIBBLE_SIZE = 4 #half a byte. (4 digits long of 1's and 0's)
42+
43+
4144def showWelcomeScreen ():
4245 userChoice = input ('\n \t Hex & Binary Converter \n Enter 1 to convert unsigned binary to hexadecimal \n Enter 2 to convert hexadecimal to unsigned binary \n Quit (any other character) \n Your choice: ' )
4346 userChoice = userChoice .lstrip (' ' ) #remove leading spaces
You can’t perform that action at this time.
0 commit comments