开发者

Convert jshort to unsigned short

开发者 https://www.devze.com 2023-01-28 12:39 出处:网络
I\'m developing a Java program that uses some native calls. Do you know an easy way to convert jshort to unsigne开发者_StackOverflow社区d short? Or, can I use as equivalents types?

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

Do you know an easy way to convert jshort to unsigne开发者_StackOverflow社区d 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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消