Skip to content

Instantly share code, notes, and snippets.

@hydrocat
Created September 15, 2015 04:05
Show Gist options
  • Save hydrocat/11d092e2d12ccb9d68ee to your computer and use it in GitHub Desktop.
Save hydrocat/11d092e2d12ccb9d68ee to your computer and use it in GitHub Desktop.
Quick print decimal in binary using C
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char* argv[] )
{
int n = atoi(argv[1]);
int i=0;
for(; i < sizeof( int ) * 8 ; i++, n <<= 1 )
{
printf("%d", n<0 ? 1 : 0 );
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment