Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <stdio.h>
int main(int argc, char **argv)
{
// A short demo showing the output of bitwise operators
// In C you can express a binary value by prepending it
// with "0b." Below are two variables using this expression
int a = 0b111100; // the number 60
int b = 0b001101; // the number 13
printf("the value of int a:\t%d\n",a);
printf("the value of int b:\t%d\n",b);
printf("Bitwise a&b:\t %d\n", a&b);// Binary AND
printf("Bitwise a|b:\t %d\n", a|b);// Binary OR
printf("Bitwise a^b:\t %d\n", a^b);// Binary XOR
printf("Bitwise a<<2:\t %d\n", a<<2);// Binary Left Shift
printf("Bitwise a>>2:\t %d\n", a>>2);// Binary Right Shift
printf("Bitwise ~a:\t %d\n", ~a);// Binary Ones Complement
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment