Ledger Nano X - The secure hardware wallet
SHARE
TWEET

set bit

krot Oct 2nd, 2019 (edited) 168 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. +Setting a bit
  2. number |= 1 << n;
  3. That will set a bit n.
  4. +Clearing a bit
  5. number &= ~(1 << n);
  6. +Toggling a bit
  7. number ^= 1 << n;
  8. +Checking a bit
  9. bit = (number >> n) & 1;
  10. +Changing the nth bit to x
  11. number ^= (-x ^ number) & (1 << n);
  12. number = number & ~(1 << n) | (x << n);
  13. std::bitset<8> x;
  14. x[1] = 1;
  15. x[2] = 0;
  16.  
  17.     bit_set(<<D/integer>>,Pos,0) ->  <<(D band bnot(1 bsl Pos))/integer>>;
  18.     bit_set(<<D/integer>>,Pos,Val) -> <<(D bor (1 bsl Pos))/integer>>.
  19.  
  20. bit_set(<<D/unsigned>>,Pos,Val) -><<(    D band bnot(1 bsl Pos) bor (Val bsl Pos)  )/unsigned>>.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top