- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
/*
Build me with
gcc -lm -o binary binary.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (int argc, char * argv[]) {
if (argc <2) {printf("\nUsage: %s 234\n\n", argv[0]); exit(1);};
int in = atoi(argv[1]);
int size,a,b,c,d,e;
size=floor(log2(in))+1;
char mass[size];
for(b=0;b<=size;b++) { mass[b]=0; }
d=size;
for(a=in;a>0;a--) { if (mass[d]==1){ for(e=size;e>=0;e--){ if (mass[e]==0) {mass[e]=1; break;} else mass[e]=0;continue;}}
else {mass[d]=1;d=size;}}
for(c=1;c<=size;c++)
{printf("%i",mass[c]);}
printf("\n");
return 0;
}