Created
June 9, 2018 01:01
-
-
Save hnw/4d613f080eb01ef10d02c21c658d7bea to your computer and use it in GitHub Desktop.
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() | |
{ | |
long i1 = -1; | |
long i2 = LONG_MIN; // -9223372036854775808 | |
unsigned long u = ULONG_MAX; // 18446744073709551615 | |
printf("%ld\n", i1>>1); // 最上位ビット維持、算術シフト (-1) | |
printf("%ld\n", i1<<1); // 算術シフトでも論理シフトでも結果は同じ (-2) | |
printf("%ld\n", i2>>1); // 最上位ビット維持、算術シフト (-4611686018427387904) | |
printf("%ld\n", i2<<1); // 最上位ビット維持せず。算術シフト? (0) | |
printf("%lu\n", u>>1); // 論理シフト (9223372036854775807) | |
printf("%lu\n", u<<1); // 論理シフト (18446744073709551614) | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment