Challenge 32

💻

Binary <-> Hexadecimal

Open in Code Editor or Copy Instructions

Create 2 functions binToHex and hexToBin to convert binary numbers to hexadecimal and vice-versa respectively. You can represent these numbers as strings

Examples:

binToHex("11110000") would return "F0"

binToHex("001101") would return "0D"

hexToBin("A1") would return 10100001

Extension:

Test your functions work by looping from hex 00 to FF and outputting their binary equivalent

Add validation - e.g. "1H" is is invalid hexadecimal number