2

I'm working in Android jni and want to convert the unsigned long long C datatype to equivalent JNI wrapper. What should the equivalent jni wrapper be ? Also when I will write the JAVA function call which will call the jni wrapper, what should be the dataype of the JAVA method parameter for this unsigned long long datatype ?

Harshad
  • 7,904
  • 3
  • 24
  • 42

1 Answers1

1

Java doesn't know unsigned. All Java numerical primitives are signed (blame Gosling). If you will really need to transport the unsigned 64bit range over JNI (that is you need [0,2^64] not only [-2^63,2^63-1]) then there is no equivalent Java wrapper and you will need to decompose the value (like uppper four bytes and lower four bytes). Otherwise you can use simply Java primitive long (JNI jlong) as it is 64bit regardless of the processor architecture.

Community
  • 1
  • 1
Pavel Zdenek
  • 7,146
  • 1
  • 23
  • 38
  • We are trying using byte[] for sending and receiving data. Is it correct ? – Harshad Jun 22 '12 at 10:16
  • Yes you absolutely can use jbyteArray. However be careful about getting the endian-ness right. JVM is big endian but you cannot assume the endianness of the underlying hardware. Though it will be most probably a low endian, which is equally inconvenient. If in doubt, do an arithmetical decomposition (that is divide and modulo by 0xFF) instead of just calling out bytes by address. – Pavel Zdenek Jun 22 '12 at 12:07
  • If it answered your question, consider accepting and improve your rate. – Pavel Zdenek Jul 03 '12 at 09:47