#include <stdio.h>
#include <stdlib.h>
typedef char byte;
byte* floatToByteArray(float f) {
byte
* ret
= malloc(4 * sizeof(byte
)); unsigned int asInt = *((int*)&f);
int i;
for (i = 0; i < 4; i++) {
ret[i] = (asInt >> 8 * i) & 0xFF;
}
return ret;
}
int main(void) {
float f = 1.0;
byte* asBytes = floatToByteArray(f);
int i;
for(i = 0; i < 4; i++) {
printf("Byte #%i: %i\n", i
, asBytes
[i
]); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnR5cGVkZWYgY2hhciBieXRlOwoKYnl0ZSogZmxvYXRUb0J5dGVBcnJheShmbG9hdCBmKSB7CglieXRlKiByZXQgPSBtYWxsb2MoNCAqIHNpemVvZihieXRlKSk7Cgl1bnNpZ25lZCBpbnQgYXNJbnQgPSAqKChpbnQqKSZmKTsKCQoJaW50IGk7Cglmb3IgKGkgPSAwOyBpIDwgNDsgaSsrKSB7CgkJcmV0W2ldID0gKGFzSW50ID4+IDggKiBpKSAmIDB4RkY7Cgl9CgkKCXJldHVybiByZXQ7Cn0KCQoKaW50IG1haW4odm9pZCkgewoJZmxvYXQgZiA9IDEuMDsKCQoJYnl0ZSogYXNCeXRlcyA9IGZsb2F0VG9CeXRlQXJyYXkoZik7CgkKCWludCBpOwoJZm9yKGkgPSAwOyBpIDwgNDsgaSsrKSB7CgkJcHJpbnRmKCJCeXRlICMlaTogJWlcbiIsIGksIGFzQnl0ZXNbaV0pOwoJfQoJCglyZXR1cm4gMDsKfQo=