I want to write a function that unpacks a char* buffer to a float* buffer. The char* buffer was originally packed as floats to bytes.
What is the best way to do this?
I have implemented integers below.
I have packed an array of 4 byte sized integers in a char* buffer.
This is the function I used to unpack it and assign it to int*.
void CharToInt(int* tar, char* src, int len) {
char* val = src;
char* end = src + len-1;
for( ; val<end; tar++,val+=sizeof(int)) {
*tar = ( (((*val) < 0) ? 256 + (*val) : (*val) ) +
(((*val+1) < 0) ? 256 + (*val+1) : (*val+1) << 8 ) +
(((*val+2) < 0) ? 256 + (*val+2) : (*val+2) << 16) +
(((*val+3) < 0) ? 256 + (*val+3) : (*val+3) << 24) );
}
}
Adding 256 to a signed byte seems to takes care of the signed char. (-128 to 127).
This is because it is the same as flipping bits and subtracting 1?
Anyway, I am looking for the float* equivalent.