stephaneAG / BitsOps

Repo dedicated to notes on bitwise operators & direct bits manipulation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BitsOps

Repo dedicated to notes on bitwise operators & direct bits manipulation

the EISA EDID edition tool is not yet written, only one helper that generates a valid manufacturer name from 3 chars

for the Hexobfusc tool, visite the following link

https://cdn.rawgit.com/stephaneAG/BitsOps/master/encoderDecoderWip.html R: to update it: https://developer.mozilla.org/en-US/docs/Web/API/Blob

to thoroughly DIGG !

Reminders

_ & - bitwise and
_ | - bitwise or
_ ^ - bitwise xor
_ ~ - bitwise not
_ << - bitwise shift left unsigned
_ >> - bitwise shift right unsigned
_ >>> - bitwise shift right signed

_ 0x.. - hex / base 16
_ 0b.. - bin / base 2

Tips

get the n bit

(x>>n) & 1

odd or even ?

if ((x & 1) == 0) {
  // even
}
else {
  // is odd
}

set n bit

y = x | (1<<n)

unset n bit

y = x & ~(1<<n)

toggle n bit

y = x ^ (1<<n)

is n bit set ?

if (x & (1<<n)) {
  // n-th bit is set
}
else {
  // n-th bit is not set
}
// or
(x & (1<<n) != 0) ? 'set' : 'not set'

turn off right-most set bit

y = x & (x-1)

turn on rigght-most unset bit

y = x | (x+1)

isolate right-most set bit

y = x & (-x)

isolate right-most unset bit

y = ~x & (x+1)

right propagate right-most set bit

y = x | (x-1)

About

Repo dedicated to notes on bitwise operators & direct bits manipulation

License:MIT License


Languages

Language:JavaScript 80.7%Language:HTML 19.3%