Created
February 20, 2012 03:24
-
-
Save calvinfroedge/1867570 to your computer and use it in GitHub Desktop.
Shift operators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
int main() | |
{ | |
int x, z, y = 2, a = 3, r; | |
x = y << 2; //Binary operation. Bits are shifted two places to the left (001 becomes 100). This evalutes to 8 | |
printf("%d \n \n", x); | |
z = a << 2; //Binary operation. a starts as 011 and bits are shifted two spaces to the left. a becomes 1100 (12) | |
printf("%d \n \n", z); | |
r = z >> 2; //Binary operation. r shifts z to spaces right. r is 3. | |
printf("%d \n \n", r); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment