package pak1;
public class Byte2Hex {
public static void main(String[] args) {
for (int i = 0; i < 256; i++) {
String s = Integer.toHexString(i & 0xFF).toUpperCase();
if (s.length() == 1) {
s = "0" + s;
}
if (i % 8 == 0) {
System.out.println();
}
System.out.print(i + "=0x" + s.charAt(0) + "" + s.charAt(1) + " ");
}
}
}
--------------------------- or :
package pak1;
public class Byte2Hex {
public static void main(String[] args) {
byte[] bt = new byte[256];
for (int i = 0; i < bt.length; i++) {
bt[i] = (byte) i;
String s = Integer.toHexString(bt[i] & 0xFF).toUpperCase();
if (s.length() == 1) {
s = "0" + s;
}
if (i % 8 == 0) {
System.out.println();
}
System.out.print(i + "=0x" + s.charAt(0) + "" + s.charAt(1) + " ");
}
}
}