Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

OldGit

macrumors newbie
Original poster
Feb 2, 2009
17
0
In java there is a method "readInt()" which returns an int from byte array. What is the equivalent method to convert bytes to int (or float or other datatype)?
 
In java there is a method "readInt()" which returns an int from byte array. What is the equivalent method to convert bytes to int (or float or other datatype)?

Assuming 4-byte ints, something like:

Code:
int i = (b[0] << 24) + (b[1] << 16) + (b[2] << 8) + b[3];

Though be aware that sizeof(int) will likely differ depending on whether you're building for simulator or device.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.