how to communicate the integer value of char from C++ to Java
843790May 21 2007 — edited May 31 2007Well, I also used the Java Programming forum for this question,
but since nobody answered, I am using another forum. What's
really the right forum for this?
I am calling a Java native executable from a C++ program.
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.
But when I recieve the char ch in Java, neither
int i = ((int)(ch)>>8) & 255
nor
int i = (int)(ch) & 255
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?
Thanks for looking at this!