Last active
August 29, 2015 14:24
Revisions
-
yenliangl revised this gist
Jul 12, 2015 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,19 @@ #include <cstdio> #include <iostream> #include <bitset> #include <cstring> #include <limits> int main(int argc, char** argv) { const int n = atoi(argv[1]); std::cout << " n = " << std::bitset<32>(n) << ", INTMAX=" << std::numeric_limits<int>::max() << ", INTMIN=" << std::numeric_limits<int>::min() << std::endl; unsigned int n1=n<<1; std::cout << " n << 1 = " << std::bitset<32>(n1) << ", decimal=" << n1 << std::endl; unsigned int n2=n>>31; std::cout << " n >> 31 = " << std::bitset<32>(n2) << ", decimal=" << n2 << std::endl; unsigned int n3=n1^n2; std::cout << " (n<<1)^(n>>31) = " << std::bitset<32>(n3) << ", decimal=" << n3 << std::endl; return 0; -
yenliangl revised this gist
Jul 12, 2015 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ #include <cstdio> #include <iostream> #include <bitset> @@ -10,7 +9,7 @@ int main(int argc, char** argv) std::cout << " n = " << std::bitset<32>(n) << std::endl; int n1=n<<1; std::cout << " n << 1 = " << std::bitset<32>(n1) << ", decimal=" << n1 << std::endl; int n2=n>>31; // 63 for 64-bits encoding std::cout << " n >> 31 = " << std::bitset<32>(n2) << ", decimal=" << n2 << std::endl; int n3=n1^n2; std::cout << " (n<<1)^(n>>31) = " << std::bitset<32>(n3) << ", decimal=" << n3 << std::endl; -
yenliangl created this gist
Jul 12, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ #include <cstdio> #include <iostream> #include <bitset> #include <cstring> int main(int argc, char** argv) { const int n = atoi(argv[1]); std::cout << " n = " << std::bitset<32>(n) << std::endl; int n1=n<<1; std::cout << " n << 1 = " << std::bitset<32>(n1) << ", decimal=" << n1 << std::endl; int n2=n>>31; std::cout << " n >> 31 = " << std::bitset<32>(n2) << ", decimal=" << n2 << std::endl; int n3=n1^n2; std::cout << " (n<<1)^(n>>31) = " << std::bitset<32>(n3) << ", decimal=" << n3 << std::endl; return 0; }