public class Test { public static void main(String[] args) { char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; byte b = -1; System.out.println("b = 0x" + hex[(b >> 4) & 0x0f] + hex[b & 0x0f]); } }
"b = 0x" + hex[(b >> 4) & 0x0f] + hex[b & 0x0f]在右移时不保留符号:
原文地址:http://blog.csdn.net/csuhanyong/article/details/39313583