-1

I am putting a long value in a byte array in my Java Code. This(byte array) will be transmitted to the native side code(C++). In this C++ code, I have to reconstruct the long value sent from Java.

How can I access the byte array and all the bytes in it and get the long value back ? please help.

Black Diamond
  • 483
  • 7
  • 25

1 Answers1

0

Something like this for a long value:

int64_t i;
memcpy(&i, transmittedByteArray, 8);
constexpr union { unsigned short s; unsigned char islittle;} chkendian{1};
if(chkendian.islittle)
    std::reverse((char*)&i,(char*)&i+8);
cshu
  • 5,654
  • 28
  • 44