Skip to content

Instantly share code, notes, and snippets.

@splitline
Created November 23, 2016 11:09
Show Gist options
  • Save splitline/3fd3bf601963b8841ea18e1e993ef3f5 to your computer and use it in GitHub Desktop.
Save splitline/3fd3bf601963b8841ea18e1e993ef3f5 to your computer and use it in GitHub Desktop.
#include <stdio.h>
long long int get_from_addr(long long int* p){
return *p;
}
char* itobs(long long int n, char *ps) {
int size = 8 * sizeof(n);
int i = size -1;
while(i+1) {
ps[i--] = (1 & n) + '0';
n >>= 1;
}
ps[size] = '\0';
return ps;
}
int main(){
double in;
while(~scanf("%lf",&in)){
double *p=&in;
long long int n=get_from_addr((long long int *)p);
char s[8 * sizeof(n) + 1];
printf("%s\n",itobs(n,s));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment