Question

I'm developing a Java program that uses some native calls.

Do you know an easy way to convert jshort to unsigned short? Or, can I use as equivalents types?

In native code I receive a jshort value and I need to use this value as GLushort.

Any advice?

Thanks.

Was it helpful?

Solution

Just add & 0xFF to it! It makes it unsigned :D

OTHER TIPS

Well, first see wikipedia. A jshort is actually a short (signed) so to convert it you have to handle negative values.

Why not use the jchar since it maps directly to a unsigned short - then you can cast directly.

jchar jC = ....;
GLushort s = (GLushort) jC;

You can just cast to GLushort in your code.

The fact that jshort is signed does not matter unless the parameter can actually be used to hold negative values and you are doing arithmetic or integer comparisons in the Java side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top