Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

/E1.cpp Secret

Created April 11, 2014 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/346d631814c54fb90263 to your computer and use it in GitHub Desktop.
Save anonymous/346d631814c54fb90263 to your computer and use it in GitHub Desktop.
int E1 () {
unsigned char a, b, c;
printf("Number (byte): ");
scanf("%hhd", &a); // This now only uses 1 byte (length of char)
printf("Bit you want to output (between 0 and 7): ");
scanf("%hhd", &b); // This now only uses 1 byte (length of char)
b = (1 << b); // This is more efficient for calculating 2^b
printf("Mask is: %d\n", b);
c= a & b;
if (c > 0) {
printf("The bit is: 1\n");
} else {
printf("The bit is: 0\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment