I wrote a program to display data in memory as binary and it worked. (It gave me immense sense of satisfaction and joy to see this work. I guess this happens to newbies who are just testing the waters). I know this isn't some terribly smart code, and I'm sure there must be surely lots of better ways to do this. Any advice and help would be great. If I've done something wrong in this program or if there is any bad programming practice, I would be happy to be corrected.
#include<stdio.h> int main() { char mychar = 'a'; int count = 0; int bitmask = 128; while (count < 8){ if (mychar & bitmask){ printf("1"); } else{ printf("0"); } bitmask = bitmask / 2; count = count +1; } return 0; }