bit-flip

cur-val bit-pos


Summary

Flip the bit at bit-pos within cur-val

Arguments

cur-val
The integer where we flip the bit in
bit-pos
The index of the bit we want to flip, with 0 being the least significant digit

Return value

An integer cur-val but with the bit at position bit-pos flipped

Examples

(bit-flip 15 2)
11

(bit-flip 11 2)
15

Bytecode

Probably only interesting to you if you want to understand more about the Nujel VM or care very much about performance.

(    0 ($get/val 'bit-xor))
(    2 ($get/val 'cur-val))
(    4 ($get/val 'bit-shift-left))
(    6 ($push/int/byte 1))
(    8 ($get/val 'bit-pos))
(   10 ($apply 2))
(   12 ($apply 2))
(   14 ($ret))