0

I am sending a long long to a byte array with other stuff to a java server. When I convert the long back at the java end its not what I am expecting. I have tested the java converter but I ObjectiveC I thought that with it been low level would be as simple as this.

uint8_t *data = alloca(sizeof(longlong));
memcpy(&data[sizeof(Byte)+1],&theLong,sizeof(long long));

Is that right or am I on the wrong tracks?

Andrew
  • 1,764
  • 3
  • 24
  • 38
  • can be helpful probably: http://stackoverflow.com/questions/362384/are-integers-in-java-little-endian-or-big-endian – lupatus Dec 06 '12 at 00:23
  • Rather than do the alloca, I'd just take the `&` of the long long and cast that to a byte pointer, to access the bytes. No need for heap allocation/disposal. Or do the regular shift/mask to get at the bytes. – Hot Licks Dec 06 '12 at 00:51
  • I had only done that so that long long could go in to a payload array with other things. But even if I did that wouldn't I still have the same problem – Andrew Dec 06 '12 at 08:03
  • Can anyone help me out here? – Andrew Dec 06 '12 at 09:59

1 Answers1

1

Maybe... Depend on the endianess... take a look here: http://en.wikipedia.org/wiki/Endianness

Elvis Dukaj
  • 7,142
  • 12
  • 43
  • 85