- 论坛徽章:
- 0
|
[color="#333333"]来源[color="#333333"]: http://www.javaresearch.org/article/showarticle.js
[color="#333333"]public final class ByteIntSwitch {
public static void main(String args[] ) {
int i = 212123;
byte[] b = toByteArray(i, 4); //整型到字节,
System.out.println( "212123 bin: " + Integer.toBinaryString(212123));//212123的二进制表示
System.out.println( "212123 hex: " + Integer.toHexString(212123)); //212123的十六进制表示
for(int j=0;j>8*i & 0xFF );
}
return bLocalArr;
}
// 将byte数组bRefArr转为一个整数,字节数组的低位是整型的低字节位
public static int toInt(byte[] bRefArr) {
int iOutcome = 0;
byte bLoop;
for ( int i =0; ijava ByteIntSwitch
212123 bin: 110011110010011011
212123 hex: 33c9b
212123 to byte:
b[0]=-101 b[1]=60 b[2]=3 b[3]=0
byte to int:212123
C:java>
C:java>
[color="#333333"]来源[color="#333333"]: http://www.javaresearch.org/article/showarticle.js
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/3072/showart_13745.html |
|