Convert a byte to it's hexadecimal equivalent in Java
Description
The following code shows how to convert a byte to it's hexadecimal equivalent.
Example
/*from w ww .j ava2 s. c om*/
public class Main {
public static void main(String[] argv) {
System.out.println(byteToHex((byte) 123));
}
public static String byteToHex(byte b) {
int i = b & 0xFF;
return Integer.toHexString(i);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »