我在 Java 中有以下代码,我需要将其转换为 C++ 才能对无符号整数进行编码。
public static int enc_uint32be( int i, byte[] dst, int di ) {
dst[di++] = (byte)((i >> 24) & 0xFF);
dst[di++] = (byte)((i >> 16) & 0xFF);
dst[di++] = (byte)((i >> 8) & 0xFF);
dst[di] = (byte)(i & 0xFF);
return 4;
}
我是java新手。我相信这个论坛上的几位专家都知道这两种语言 - 谁能帮我翻译一下。
最佳答案
这取决于您计划使用的数据类型,但如果您只是更改:
byte[] dst
到
unsigned char dst[]
在函数声明中,那么它应该表现相同(并将函数中的字节用法也更改为 unsigned char
)。
关于java - 编码无符号整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10825825/