有些问题是为什么Java不支持无符号类型以及有关处理无符号类型的一些问题.我做了一些搜索,看起来Scala也不支持无符号数据类型.Java和Scala的语言设计中的限制,生成的字节码,还是JVM本身?是否有一些语言在JVM上运行,并且在其他方面与Java(或Scala)相同,但是支持无符号原始数据类型?
我想知道为什么Hashtable避免使用负哈希码?
int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length;
Run Code Online (Sandbox Code Playgroud)
哪里(hash & 0x7FFFFFFF)使有符号位为0为正,但为什么我们不能将带符号的32位整数视为无符号?甚至使用模块化技巧使其变得积极.例如,
public static long int_mod(int hashcode, int tab_length){
return (hashcode % tab_length + tab_length) % tab_length;
}
Run Code Online (Sandbox Code Playgroud) 为什么 C# Marshal.Copy 例程没有任何重载用于从非托管内存指针复制到 16 位托管无符号整数数组?
前任:
Copy(IntPtr, Byte[], Int32, Int32) Copies data from an unmanaged memory pointer to a managed 8-bit unsigned integer array.
Copy(IntPtr, Char[], Int32, Int32) Copies data from an unmanaged memory pointer to a managed character array.
Copy(IntPtr, Double[], Int32, Int32) Copies data from an unmanaged memory pointer to a managed double-precision floating-point number array.
Copy(IntPtr, Int16[], Int32, Int32) Copies data from an unmanaged memory pointer to a managed 16-bit signed integer array.
Copy(IntPtr, Int32[], Int32, …Run Code Online (Sandbox Code Playgroud) 我试图将CRC8函数从C转换为Java.
我从硬件制造商那里得到了这个代码:
uint8_t CRCCalc (uint8_t* pointer, uint16_t len) {
uint8_t CRC = 0x00;
uint16_t tmp;
while(len > 0) {
tmp = CRC << 1;
tmp += *pointer;
CRC = (tmp & 0xFF) + (tmp >> 8);
pointer++;
--len;
}
return CRC;
}
Run Code Online (Sandbox Code Playgroud)
我的Java代码是:
private int getCheckSum(byte[] data) {
int tmp;
int res = 0;
for(int i = 0; i < data.length; i++) {
tmp = res << 1;
tmp += 0xff & data[i];
res = (tmp & 0xff) + (tmp …Run Code Online (Sandbox Code Playgroud) 我需要转换integer到byte并在文件中写字节,但是当我转换大于128的数字节转换为负数.我需要使用unsigned char,但我不知道如何.在c ++我们写,unsigned但它在java中是怎么回事?