3 ms·
You probably want to look at sizeof( float ) and sizeof( int ). My guess is they'll be different, so do something like: #include <stdio.h> #include <std
by OhMeadhbh 3y ago
You probably want to look at sizeof( float ) and sizeof( int ). My guess is they'll be different, so do something like:
#include <stdio.h>
#include <stdint.h>
int main() {
uint32_t i = 1200053440 + 64;
float * fp = (float *) &i;
float f = *fp;
printf( "%ld %ld %ld\n", sizeof( i ), sizeof( fp ), sizeof( f ) );
printf( "%08X %d %f\n", i, i, f );
return( 0 );
}
But I'm nitpicking. Your intent was clear from the much smaller example you gave.
- OhMeadhbh 3y agoHunh. I just discovered that when you cast the 32 bit 2's complement -273613110 as an IEEE 754-2008 binary32 float, you get -109554765609536775148540002304.0 which, when you look at it's in-memory representation as a series of octets on a little-endian machine, it's CAFEBOEF. How to get to DEADBEEF is left as an exercise for the reader. The next time I need a floating point constant, I'm picking -109554765609536775148540002304.0.
- gpderetta 3y agoon most (but of course not all) machines a float is an IEEE 32 bit float and an int is also a 32 bit integer.