To convert a hexadecimal digit to a binary value, look up the digit in a conversion table and write down the corresponding binary value. Repeat this process for each hexadecimal digit in the number, and combine the resulting binary values to get the binary equivalent of the original hexadecimal number.
To convert a hexadecimal number to a binary number:
- Write down the binary values for each hexadecimal digit
Hexadecimal Digit | Binary Value |
---|---|
0 | 0000 |
1 | 0001 |
2 | 0010 |
3 | 0011 |
4 | 0100 |
5 | 0101 |
6 | 0110 |
7 | 0111 |
8 | 1000 |
9 | 1001 |
A | 1010 |
B | 1011 |
C | 1100 |
D | 1101 |
E | 1110 |
F | 1111 |
- Replace each hexadecimal digit with its corresponding binary value.
- The resulting string of binary digits is the equivalent of the original hexadecimal number in binary format.
Find the binary value of AF185:
Number hexadecimal: | A | F | 1 | 8 | 5 |
Result: | 1010 | 1111 | 0001 | 1000 | 0101 |
Example in Javascript code:
function hexToBinary(hexString) {
const decimalNumber = parseInt(hexString?.toUpperCase(), 16);
const binaryString = decimalNumber.toString(2);
return binaryString;
}
Example in C# code:
public string HexToBinary(string hexString)
{
int decimalNumber = int.Parse(hexString, System.Globalization.NumberStyles.HexNumber);
string binaryString = Convert.ToString(decimalNumber, 2);
return binaryString;
}