且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将整数转换为无符号的32位大字节序字节数组

更新时间:2022-12-15 08:51:14

在Java中,整数是带符号的,并且是大端的.单数以二进制补码格式编码.要将二进制补码转换为无符号数,只需遵循以下规则:

In Java, integer is signed and big endian. Singed number are encoded in two's complement format. To convert a two's complement number to unsigned number, just follow the following rules:

如果要使用无符号表示,只需遵循规则即可获取无符号编号.由于整数已经在big endian中,因此只需将结果分成4个字节即可.

If you want a unsigned representation, just following the rules to get the unsigned number. As the integer already in big endian, just split the result in 4 bytes.