hello guys this is my program and this simply converts
int to binary however I could not understand
printf( " %i ", (arg1 & 1 << x ) > 0 ? 1 : 0 );
the 1 near arg1 , what is this 1 doing there ...
my other question is can we modify this into float - binary converter?
#include <stdio.h>
#include <stdlib.h>
void main( int argc, char *argv[] )
{
int arg1, x;
if( argc == 1 )
{
puts( "BINARY num = displays num in binary form." );
exit( 1 );
}
arg1 = atoi( argv[1] );
printf( "INTEGER: %i\n", arg1 );
printf( " BINARY:" );
printf( " " );
for( x = 7; x > -1; x-- )
printf( " %i ", (arg1 & 1 << x ) > 0 ? 1 : 0 );
}
Start Free Trial