Because the value of d (the number of digits to output) is 6, this loops 6 times. Steps 5 and 6 are identical and just output 0 because x is already 0 after step 4. The red box highlights the output and shows how 010100 is output.
If you feel confident you can simplify this further with two changes. Turn the while into a for loop (with no initalizing part!) and condense the if into a one line statement. The brackets around the x & 1 are needed as + has a higher precedence than binary & so if you remove them, it will generate rubbish. This works because you can use ints and chars together in this way. The longer if statement is easier to understand and more portable and would be my preference
void PrintBinary(int x,int d)
{
char buffer[33];
int index=0;
for (;d>0;d--)
{
buffer[index++] = '0'+(x & 1) ;
x >>= 1;
}
while (index >0 )
printf("%c",buffer[--index]) ;
printf("B\n") ;
return;
}
On the next page : An example of and, or and xor.


