I asked questions about hexadecimal and bitwise manipulation (here and elsewhere) last week, trying to wrap my head around their representation in Java. After much thought and disappointment, I should ask for the last time how to perform logical arithmetic on bits that should be unsigned, but presented as signed in Java.
Good: I port the program in C # to Java. The program deals with processing bitmap images, and since so much of the data in the application is presented as an unsigned 8-bit integer. There are many suggestions to use the data type in Java instead to "mimic" as close as possible to an 8-byte unsigned value. byteshort
I do not believe that this is possible for me, since C # code performs various shift operations and And with my byte data. For example, if it datais a byte array, and this code block exists in C #:
int cmdtype = data[pos] >> 5;
int len = (data[pos] & 0x1F) + 1;
if (cmdtype == 7)
{
cmdtype = (data[pos] & 0x1C) >> 2;
len = ((data[pos] & 3) << 8) + data[pos + 1] + 1;
pos++;
}
, data short , Java. , , 8- , 16- , . ? , " " byte 0XFF char Java , , .
, , . , JNI. , uint8_t # byte.
JNI? , , . Java, ? , , .
.