Is there any method in Java that will convert hexadecimal characters to binary characters?
Location: http://www.jguru.com/faq/view.jsp?EID=451751 Created: Jul 8, 2001 Modified: 2001-08-18 19:07:01.613 Author: Tim Rohaly (http://www.jguru.com/guru/viewbio.jsp?EID=10) Question originally posed by Sunil R (http://www.jguru.com/guru/viewbio.jsp?EID=446378 You can use Integer.parseInt() or Long.parseLong() to convert a hexadecimal representation to a 4-byte int or an 8-byte long, respectively. For example, the Java class file magic number 0xCAFEBABE can be converted to the long value 3405691582 using long magic = Long.parseLong(“CAFEBABE”, 16); where the second argument to the method represents the radix used to encode the first parameter (in this case, base 16, or hexadecimal). You can also convert hexadecimal number directly into Integer or Long objects using the methods Integer.decode() or Long.decode(), respectively. If you wish to subsequently print out these values as a String in base 2 (binary), you can use either Integer.toBinaryString() or Long.toBinaryString(). See the
Related Questions
- Why does my application sometimes receive a NativeSeqFile error when using JRIO and the Remote Method Invocation (RMI) - Java Remote Method Protocol (JRMP) to access MVS datasets?
- Is there any method in Java that will convert hexadecimal characters to binary characters?
- How to convert decimal number to binary?