convert Binary,Hex and Octa to java data types

144 views Asked by At

I need to develop one utility service that takes binary or hex or oct as input and that need to be converted into java data types with readable formats (binary to int,binary to long etc). please let me know if there is any library to take care with minimum code efforts instead of using java api for each format that could be helpful.

1

There are 1 answers

0
Madhan On BEST ANSWER

Java's Integer class would do all of what you've asked

Integer.
 parseInt("0", 10) returns 0
 parseInt("473", 10) returns 473
 parseInt("+42", 10) returns 42
 parseInt("-0", 10) returns 0
 parseInt("-FF", 16) returns -255
 parseInt("1100110", 2) returns 102
 parseInt("2147483647", 10) returns 2147483647
 parseInt("-2147483648", 10) returns -2147483648
 parseInt("2147483648", 10) throws a NumberFormatException
 parseInt("99", 8) throws a NumberFormatException
 parseInt("Kona", 10) throws a NumberFormatException
 parseInt("Kona", 27) returns 411787

    int x = 10101;
    Integer.toBinaryString(x);
    Integer.toHexString(x);
    Integer.toOctalString(x);
    Integer.toUnsignedLong(x);