在 Java 中使用 Unsigned int 32 位?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11759053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 06:16:05  来源:igfitidea点击:

Using Unsigned int 32 bit in Java?

javacharbitunsigned

提问by user1568522

Possible Duplicate:
Converting 32-bit unsigned integer (big endian) to long and back

可能的重复:
将 32 位无符号整数(大端)转换为 long 和 back

I want to translate this expression in Java

我想用 Java 翻译这个表达式

char tab[100];
tab[10] = '\xc0';

tab[48] = '\x80';

uint32_t w = 0x67452301;

uint32_t x = 0xefcdab89;

uint32_t y = 0x98badcfe;

uint32_t z = 0x10325476;

a = ((b & c) | (~b & d)) + (*(uint32_t*)(tab+0x00)) + a - 0x28955B88;

a = ((a << 0x07) | (a >> 0x19)) + b;

I'have tried this but...

我试过这个,但...

char[] tab = new char[64];

 tab[10] = (char) 0xc0; 
 tab[48] = (char) 0x80; 

but the value is not the right one, is there another way to assign \0x80 in a char[] ? How can i interprete this kind of cast in java ((uint32_t)) ?

但该值不正确,是否有另一种方法可以在 char[] 中分配 \0x80 ?我如何在 java ( (uint32_t)) 中解释这种类型的转换?

Many thanks !

非常感谢 !

回答by AlexR

Type intis 4 bytes, i.e. 32 bits in java. So the regular 32bits int from C may be translated as regular int in java.

类型int为 4 个字节,即 java 中的 32 位。因此,C 中的常规 32 位 int 可以在 java 中转换为常规 int。

Unsigned int is not supported by java language, so use longthat contains 8 bytes to represent unsigned 32 bit variables from C.

java 语言不支持无符号整数,因此使用long包含 8 个字节的它来表示来自 C 的无符号 32 位变量。