All pastes #508257 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-05-24 22:34 UTC
rendered paste body

#include <stdio.h>
#include <stdlib.h>

int main (void) {

float fl, fl2;
fl = -0.2;
short *sptr = (short * )&fl;
short fract = (*sptr << 0) & 0x7FFFFF;
short exp   = (*sptr << 23) & 0xFF;
short sign  = (*sptr << 31) & 0x1;
printf("fract=%d, exp=%d, sign=%d\n", fract, exp, sign);


fl2 = (sign == 0 ? 1 : -1) * 2^exp * fract;

printf("conv=%0.2f\n", fl2);

return 0;
}