Skip to content

Instantly share code, notes, and snippets.

@sojohnnysaid
Created January 5, 2018 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sojohnnysaid/c086381016390fd81fc610798e1fd27b to your computer and use it in GitHub Desktop.
Save sojohnnysaid/c086381016390fd81fc610798e1fd27b to your computer and use it in GitHub Desktop.
#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