Skip to content

Instantly share code, notes, and snippets.

@jessedhillon
Created February 1, 2016 22:03
Show Gist options
  • Save jessedhillon/386fa964e822e529f6c1 to your computer and use it in GitHub Desktop.
Save jessedhillon/386fa964e822e529f6c1 to your computer and use it in GitHub Desktop.
FP bit manipulation
/*
* $ gcc shift_float.c
* $ a.out
*/
#include <stdio.h>
void main() {
float f = 3.0;
long l;
printf("begin : %f\n", f);
l = *(long *)&f;
l >>= 1;
f = *(float *)&l;
printf("lshift: %ld\n", l);
printf("fshift: %f\n", f);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment