C的无符号数据类型int,short,byte 转为 Java对应的数据long,char,short
生活随笔
收集整理的這篇文章主要介紹了
C的无符号数据类型int,short,byte 转为 Java对应的数据long,char,short
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
//從網(wǎng)絡中讀取C的無符號int,short,byte字節(jié)數(shù)組,相應轉(zhuǎn)換成java的long,char,short short anUnsignedByte = 0; char anUnsignedShort = 0; long anUnsignedInt = 0; int firstByte = 0; int secondByte = 0; int thirdByte = 0; int fourthByte = 0; byte buf[] ="1234567890".getBytes();//如:讀網(wǎng)絡字節(jié)數(shù)據(jù) int index = 0; firstByte = (0x000000FF & ((int)buf[index])); anUnsignedByte = (short)firstByte; index++;firstByte = (0x000000FF & ((int)buf[index])) ; secondByte = (0x000000FF & ((int)buf[index+1])); index = index+2; anUnsignedShort = (char) (firstByte << 8 | secondByte); firstByte = (0x000000FF & ((int)buf[index])) ; secondByte = (0x000000FF & ((int)buf[index+1])); thirdByte = (0x000000FF & ((int)buf[index+2])); fourthByte = (0x000000FF & ((int)buf[index+3])); index = index+4; anUnsignedInt = ((long) (firstByte << 24 | secondByte << 16| thirdByte << 8 | fourthByte)) & 0xFFFFFFFFL;
?
總結
以上是生活随笔為你收集整理的C的无符号数据类型int,short,byte 转为 Java对应的数据long,char,short的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++之字节对齐与结构体大小
- 下一篇: java的int、char、long、f