Skip to content

Instantly share code, notes, and snippets.

@wizardjedi
Created March 11, 2019 17:21
Show Gist options
  • Save wizardjedi/37b02af498a8a0c42757908a20c60609 to your computer and use it in GitHub Desktop.
Save wizardjedi/37b02af498a8a0c42757908a20c60609 to your computer and use it in GitHub Desktop.
bit operations
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