Convert an integer into binary representation

Submitted by:Pitter Alderson

Date added:02 January, 2016

Category:C

Source code to convert an integer into binary representation

Tags: convert integer , binary representation

Code Snippet:

void display_binary_n(int dec)
{
const int size = sizeof(int) * 8 ;
unsigned int current;
int i;
for( i = size - 1 ; i >= 0 ; i--)
{
current = 1<<i;
printf("%d",( (current & dec) != 0) ? 1: 0);
}

}
 
 

Comments