Created
May 5, 2015 10:54
-
-
Save ba0f3/189adaf4f86771aa8f4b to your computer and use it in GitHub Desktop.
https://github.com/Araq/Nim/blob/b13c51cc2aa1f47bc95c4c45d02c04bc3cff783e/tests/misc/tradix.nim
This file contains hidden or 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
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