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
1 2 3 4 5 6 7 8 9 10 11 12 |
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
1 2 3 |
Hexadecimal equivalent of byte = 4b |
Example 2
1 2 3 4 5 6 7 8 9 10 11 12 |
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
1 2 3 |
Hexadecimal equivalent of byte = 7d |
No Comments