public static String byte2HexString(byte[] b){
String ret = "";
for(int i=;i<b.lenght;i++){
String hex = Integer.toHexString(b[i]&0XFF);
if(hex.length()==){
hex = ''+hex;
}
ret+=hex.toUpperCase();
}
return ret;
}

1  1个字节8位          1个BYTE与上2个hex字符
  1 个HEX字符4位

2 Integer.toHexString(int ---);

作用 int(十进制有符号)  ---> String (十六进制)

3 byte ==>int

byte b;

int i=b&0Xff;

分析 :byte -->8 位 int 32位

byte转int位数不够要补位 补位有偏差 故需要清零多出的高24位 即与上0xFF

补码:

1111 1111

[ 1111 1111 ] [ 1111 1111 ] [ 1111 1111 ] [1111 1111]

0XFFFF FFFF与上0Xff高24位清零

&与

& -->

& -->

& -->

& --->

两边都成立才可以为真

| -->
| -->
| -->
| -->
两边只有一方成立即可

byte b = 24;

int i = b&FF; 清零高24位

-2

字节       1111 1110 补码

字 1111 1111  1111 1110 补码

字节       1000 0010 源码

字   0000 0000  1000 0010 源码

            二进制      十进制

1B byte = 8 bit    1B = 8bit    1B=8bit

1 KB =1024B     1KB= 2^10B   1KB = 10^3B 

1MB =1024kb      1MB = 2^20B  1MB=10^6b

1GB = 1024mb    1GB = 2^30B    1GB = 10^9B

1TB = 1024GB    1TB= 2^40B      1TB= 10^12B

1024          2^10      10^3

hex string  == byte

1 hex string  -- integer    Integer i = Integer.parseInt("EA",16);

2 integer -- byte        Byte b = i.byteValue();

Byte HexString        byte b = -22;

1 byte -->integer        Integer i = b.intValue();

2 integer -->string       String newII = Integer.toHexString(ii).subString(6,8);

04-30 06:31