cgray1223
asked on
Using Java what is the best approach for doing hexadecimal to bit conversion?
Hello,
I have a hexadecimal String that I'm converting to its bit representation. The Most significant byte iss Byte 0 and the most significant bit is bit 7. So bits 1-4 which is the lower nibble. For example, if I have a hex String of "01" and I want to get the decimal value of bits 1-4 of byte 1, I would use the below:
String tmp = "0145";
Integer value = Integer.parseInt(tmp.subst ring(1, 2), 16);
My question would be is there a built in Java function or best practice to then get the value (0 or 1) of bit 4 of the value variable above? I have various bits I need to inspect to see if the values are 0 or 1.
I have a hexadecimal String that I'm converting to its bit representation. The Most significant byte iss Byte 0 and the most significant bit is bit 7. So bits 1-4 which is the lower nibble. For example, if I have a hex String of "01" and I want to get the decimal value of bits 1-4 of byte 1, I would use the below:
String tmp = "0145";
Integer value = Integer.parseInt(tmp.subst
My question would be is there a built in Java function or best practice to then get the value (0 or 1) of bit 4 of the value variable above? I have various bits I need to inspect to see if the values are 0 or 1.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What you could use is the BitSet class, or convert the value to a binary string and use charAt() method