Created
December 1, 2012 00:28
-
-
Save CatTail/4179750 to your computer and use it in GitHub Desktop.
Javascript: bitshift
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
var dec1 = 5234542352345; | |
var bin1 = dec1.toString(2); | |
// chop into 32 bit | |
var bin2 = bin1.slice(bin1.length-32); | |
var dec2 = parseInt(bin2, 2); | |
var dec3 = dec2 >> 0; | |
var bin3 = dec3.toString(2); | |
console.log(dec1); | |
console.log(dec2); | |
console.log(dec3); | |
console.log(bin1); | |
console.log(bin2); | |
console.log(bin3); | |
// Output: | |
// 5234542352345 | |
// 3272185817 | |
// -1022781479 | |
// 1001100001011000011000010011001011111011001 | |
// 11000011000010011001011111011001 | |
// -111100111101100110100000100111 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment