Skip to content

Instantly share code, notes, and snippets.

@hyzhak
Last active September 13, 2018 22:57
Show Gist options
  • Save hyzhak/346c996e9520a313edc4f1a631af1807 to your computer and use it in GitHub Desktop.
Save hyzhak/346c996e9520a313edc4f1a631af1807 to your computer and use it in GitHub Desktop.
limitations of binary operations in js
// 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
# 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