|
Decimal to Hex Conversion
The following example shows how to convert a number in Decimal system to Hexa decimal system and vice versa.
|
package com.bethecoder.tutorials.core.integer;
public class Integer2Hex {
/**
* @param args
*/
public static void main(String[] args) {
int num = 21;
String str = Integer.toHexString(num);
System.out.println(num + "(decimal) in hex : " + str);
num = Integer.parseInt(str, 16);
System.out.println(str + "(hex) in decimal : " + num);
}
}
|
| |
It gives the following output,
21(decimal) in hex : 15
15(hex) in decimal : 21
|
|