hex conversuion in java

+2 votes
asked Jul 27, 2013 in JAVA by jonathan (3,105 points)

        How to convert hex format into integer,string etc?

1 Answer

0 votes
answered Jul 27, 2013 by admin (8,115 points)


How to convert from decimal to hex

String hexNumber = ...
int decimal = Integer.parseInt(hexNumber, 16);
System.out.println("Hex value is " + decimal);

How to convert from decimal to hex

int i = ...
String hex = Integer.toHexString(i);
System.out.println("Hex value is " + hex);

How to convert a long to and from hex

In case you need it, the Long class has Long.parseLong() and Long.toHexString() analogous to the Integer methods above.