Convert an integer into binary representation source code

This snippet submitted by Elabed Soufiane on 2006-11-26. It has been viewed 5022 times.
Rating of 6.5 with 17 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

Add a snippet!