Last active
March 22, 2018 22:03
-
-
Save sorindragan/73a6e59b49fa48b4dd501929ab4eae6a to your computer and use it in GitHub Desktop.
A small test for understanding bytes shifting and when you get an overflow.
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> | |
#include<limits.h> | |
int main(void) { | |
unsigned int x = 1; | |
int x2 = 1; | |
printf("unsigned: %u\n", x << 31); | |
printf("signed:(-1) %d\n", (x2 << 31) - 1); | |
printf("signed: %d\n", x2 << 31); | |
printf("MAX_INT: %d\n", INT_MAX); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment