WLJS LogoWLJS Notebook

BitFlip

BitFlip[n, k] flips the bit corresponding to the coefficient of 2^k in the integer n.

Examples

Flip bit position:

BitFlip[5, 1]
(* 7 *)

Binary representation:

IntegerDigits[5, 2]
(* {1, 0, 1} *)
IntegerDigits[BitFlip[5, 1], 2]
(* {1, 1, 1} *)

Please visit the official Wolfram Language Reference for more details.

On this page