Last active
September 13, 2018 22:57
-
-
Save hyzhak/346c996e9520a313edc4f1a631af1807 to your computer and use it in GitHub Desktop.
limitations of binary operations in js
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
// Binary shifting | |
1 << 30 | |
// 1073741824 | |
1 << 31 | |
// -2147483648 | |
1 << 32 | |
// 1 | |
// Power | |
Math.pow(2, 30) | |
// 1073741824 | |
Math.pow(2, 31) | |
// 2147483648 | |
Math.pow(2, 32) | |
// 4294967296 | |
// In other words | |
1 << 32 === Math.pow(2, 32) | |
// false |
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
# as you can see python doesn't have such limitations for binary operation | |
# and sometimes you may prefer to process your binary data inside of python then in js | |
1 << 1024 | |
# 179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment