Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to communicate the integer value of char from C++ to Java

843790May 21 2007 — edited May 31 2007
Well, 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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 28 2007
Added on May 21 2007
16 comments
476 views