Skip to content

Instantly share code, notes, and snippets.

@ba0f3
Created May 5, 2015 10:54
Show Gist options
  • Save ba0f3/189adaf4f86771aa8f4b to your computer and use it in GitHub Desktop.
Save ba0f3/189adaf4f86771aa8f4b to your computer and use it in GitHub Desktop.
proc testBit(w, i: int): bool {.inline.} =
result = (w and (1 shl (i %% (8*sizeof(int))))) != 0
proc setBit(w: var int, i: int) {.inline.} =
w = w or (1 shl (i %% (8*sizeof(int))))
proc resetBit(w: var int, i: int) {.inline.} =
w = w and not (1 shl (i %% (8*sizeof(int))))
when isMainModule:
var x = 0x3
for i in 0..sizeof(x):
echo x.testBit(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment