Came across this showbits() function in the book im using to learn C. None of the compilers recognize it. The actual code for the function is given in the book as well.
I tried to combine the two by putting function's code in header file. I have been unsucessful so far as I don't quite understand bitwise operators. Please help me compile this if you know what is going on in this function's code.
Thanks
/* prog 2.1 */
#include <stdio.h>
#include "prog2.1.h"
int main()
{
unsigned char j;
for (j=0; j<=5; j++)
{
printf ("\nDecimal %d is same as ",j);
showbits(j);
}
return 0;
}
/* prog2.1.h */
void showbits (unsigned char n)
{
unsigned char i,k, andmask;
for (i = 7; i >= 0; i--)
{
andmask = i << 1;
k = n & andmask;
k == 0? printf ("0"):printf ("1");
}
}