Convert an integer into binary representation source code

This snippet submitted by Elabed Soufiane on 2006-11-26. It has been viewed 13179 times.
Rating of 5.0 with 91 votes

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);
	} 
	
}
 
 
 




More C and C++ source code snippets