var bit = [var _ = 1]; for (var i = 1; i < 32; i += 1) append(bit, _ += _); # returns number as bit string: bits.string(6) -> "110" var string = func(n) { if (!n) return '0'; var s = ""; while (n) { s = ((var v = int(n / 2)) + v != n) ~ s; n = v; } return s; } # checks whether bit is set in number var test = func(n, b) { n /= bit[b]; return int(n) != int(n / 2) * 2; } # returns number with bit set var set = func(n, b) n + !test(n, b) * bit[b]; # returns number with bit cleared var clear = func(n, b) n - test(n, b) * bit[b]; # returns number with bit toggled var toggle = func(n, b) test(n, b) ? n - bit[b] : n + bit[b]; # returns number with bit set to value var switch = func(n, b, v) n - (test(n, b) - !!v) * bit[b];