how to convert the value of an unsigned char in C++ to Java
843829May 21 2007 — edited May 22 2007Well, I also used the Networking forum for this question,
but I was told it belongs to the JNI forum.
I would like to communicate the red, green, and blue values of an image, which are unsigned chars in my C++ program (varying between 0 and 255) to my Java program.
I first convert the unsigned chars in my C++ program to chars.
Unfortunately, chars in C++ are 1 byte and chars in Java are 2 bytes and I might have to reverse the order of bytes. However, at least they are unsigned.
But when I recieve the char ch in Java, neither
int i = (int)(ch)>>8 (looking at the first byte)
nor
int i = (int)(ch)
seems to give the same value as the value of the unsigned char in C++.
What's a correct and fast way to make this communication?
Can I receive the char as a byte by in Java, and use
int i = ((int)by) & 255?
Thanks for looking at this!