Convert byte back to int in ANdroid NDK?

Go To StackoverFlow.com

0

I am passing a jbyte variable to a function in c inside the android NDK C file. I want to convert this byte variable to int. How to do that?

2012-04-04 05:36
by James
Clarification on your question. You are passing a byte variable from java to C. In your JNI code, you want to use it. What is stopping you from simply assigning int x = myjnibyte - jogabonito 2012-04-04 08:19
I am passing a jstring from java. then converting it to jbyte inside c, then using that variable to call a C function inside the native Code. The C function expects an int but i need an int from the jbyte - James 2012-04-04 09:29
I believe that the C function will take the jbyte without any issue. At most you will have to typecast. Please post some code, in case I haven't understood your problem. What is the error you see - jogabonito 2012-04-04 10:21


0

try this

 char buf[512];
jint dest_size = env->GetArrayLength(ba);
if (dest_size < sizeof(buf)) {
jbyte* dest_data = env->GetByteArrayElements(ba, NULL);
if (NULL != dest_data) {
memset(buf, 0x00, sizeof(buf));
memcpy(buf, dest_data, (int)dest_size);
// use buffer here
env->ReleaseByteArrayElements(ba, dest_data, 0);
}
2012-04-04 05:53
by user1203673
I am getting these errors error: request for member 'GetArrayLength' in something not a structure or union error: request for member 'GetByteArrayElements' in something not a structure or union request for member 'ReleaseByteArrayElements' in something not a structure or union... Should I include something - James 2012-04-04 06:00
try by passing jbyte* dest_data = env->GetByteArrayElements(ba, 0) - user1203673 2012-04-04 07:10
Ads