From: Troy G. <tro...@gm...> - 2010-11-30 15:45:52
|
I have a char array in Objective C with this: char[] {0, 37, 0, 0}. This is later passed to the readInt__ method in java_io_DataInputStream. This results in 9472 through the Simulator. On the Java side, I wrote a test and this results in 2424832. It appears the byte order is being reversed since Java reads and writes everything in byte order. It seems like the following code needs to be reversed to match Java. So instead of p being p[0] = 0, p[1] = 25, p[2] = 0, p[3] = 0 it would be p[0] = 0, p[1] = 0, p[2] = 25, p[3] = 0. This would correctly convert on the iPhone. I posted what the new method could look like although I didn't test it. *original* - (int) readInt__ { int d; unsigned char* p = (unsigned char*) &d; for (int i = 0; i < 4; i++) { int v = [target read__]; *p++ = (unsigned char) v; } return d; } to *new* - (int) readInt__ { int d; unsigned char* p = (unsigned char*) &d; for (int i = 4; i > 0; i--) { int v = [target read__]; p[i-1] = (unsigned char) v; } return d; } * * * * |