Skip to content

Instantly share code, notes, and snippets.

@sorindragan
Last active March 22, 2018 22:03
Show Gist options
  • Save sorindragan/73a6e59b49fa48b4dd501929ab4eae6a to your computer and use it in GitHub Desktop.
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.
#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