19 Aug Java Program to convert a byte to hexadecimal equivalent
The toHexString() method in Java converts a byte to hexadecimal equivalent. Following are some examples with output:
Example 1
public class Demo {
public static void main(String[] args) {
byte b = 75;
int i = b & 0xFF;
System.out.println("Hexadecimal equivalent of byte = "+Integer.toHexString(i));
}
}
Output
Hexadecimal equivalent of byte = 4b
Example 2
public class Demo {
public static void main(String[] args) {
byte b = 125;
int i = b & 0xFF;
System.out.println("Hexadecimal equivalent of byte = "+Integer.toHexString(i));
}
}
Output
Hexadecimal equivalent of byte = 7d
No Comments