View Full Version : byte stream to int
OldGit
Feb 19, 2009, 07:39 PM
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)?
jnic
Feb 20, 2009, 05:18 AM
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:
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.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.