I have been working with InputStreams in Objective-C and seem to have taken the wrong step into the processing of the received data.
I am receiving chunks of bytes, which are read and converted to datatypes, as integers, floats, doubles etc.
So far my process is like this:
readBuffer = (uint8_t *) malloc(4);
memset(readBuffer, 0, 4);
while (length < byteLength) {
length = [InputStream read:readBuffer 4];
}
[something fourByteUint8ToLong:readBuffer];
Now in order to do some converting from the 4-bytes to long
- (long) fourByteUint8ToLong:(uint8_t *) buffer
{
long temp = 0;
temp |= buffer[0] & 0xFF;
temp <<= 8;
temp |= buffer[1] & 0xFF;
temp <<= 8;
temp |= buffer[2] & 0xFF;
temp <<= 8;
temp |= buffer[3] & 0xFF;
return temp;
}
Is there not an easier way to handle this by using the objective-C classes?
In that case how? 8-bytes -> double, 4-bytes -> float.
Thanks in advance.
Problem solved by using
CoreFoundation.hclass function: