CSDN博客

img naxin

CLASS: Byte2Hex

发表于2004/10/13 17:15:00  1092人阅读


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) + " ");
    }
  }
}

阅读全文
0 0

相关文章推荐

img
取 消
img