| ResourceFunction["BitFlip"][n,p]
flips the pth bit of integer n. |
Details and Options
The lowest bit of integer n (e.g. signifying 20) is flipped with p=0.
Examples
Basic Examples
Flip the 0th bit of the number 2, from a zero to a one:
Flip the 0th bit of the number 3, from a one to a zero:
Starting with the number zero, flip positional bits:
Scope
Flip the bit associated with 24:
Flip the bit associated with 27:
Applications
Compute the Hamming-distance between a random integer and the same number with a single random bit flipped:
Publisher Information