One hex digit represent 4 binary digits. The max value a hex can have is F (decimal 15) which is 1111 in binary. The way I approach it is to use base 10 (decimals) as an intermediary between them like this: F = decimal 15, decimal 15 = 1111 binary E = decimal 14, decimal 14 = 1110 binary D = decimal 13, decimal 13 = 1101 binary So if you have a larger hex number, you just apply this to each hex digit. 0x4A: 4 = decimal 4 = 0100 binary A = decimal 10 = 1010 binary Answer = 0100 1010 0xEC13 E = decimal 14 = 1110 binary C = decimal 12 = 1100 binary 1 = decimal 1 = 0001 binary 3 = decimal 3 = 0011 binary Answer = 1110 1100 0001 0011 Owen
Originally posted by Sathya Ramanathan: Hi Guys, Can anyone tell me how to convert a Hexadecimal Number to a binary number. Thanks in advance Sathya Texas Tech University
The Integer.parseInt( String s, int radix ) method can be used to convert a hexadecimal String representation of a number to an int. The Integer.toBinaryString( int i ) method can then be used to convert that int to a binary representation in a String.
posted 18 years ago
Thank you Owen. That was a very clear description on how to do the conversion. Sathya Texas Tech University
New rule: no elephants at the chess tournament. Tiny ads are still okay.
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps