Created
March 11, 2019 17:21
-
-
Save wizardjedi/37b02af498a8a0c42757908a20c60609 to your computer and use it in GitHub Desktop.
bit operations
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
console.log("Hello"); | |
var offset = 7; | |
var ar = [0xfd, 0x23]; | |
var myVal = ar[0]<<8 | ar[1]; | |
console.log(myVal); | |
var read = 4; | |
// 1 | 1 1 0 0 0 0 0 0 | |
// 16-7 = 9-3=6; | |
console.log("Shift", (16 - offset - read)); | |
console.log("And", ((1 << read)-1)); | |
var newVal = (myVal >> (16 - offset - read)) & ((1 << read) - 1); | |
console.log(newVal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment