WOLFRAM

BitFlip[n,k]

flips the bit corresponding to the coefficient of in the integer n.

Details

  • BitFlip changes an individual bit in an integer(from 0 to 1 and 1 to 0).
  • The lowest bit of integer n (e.g. signifying 2^0) is flipped with k=0.
  • BitFlip[n,k] changes the bit k places from the right. For negative k specifications, the position is counted from the left, beginning with the final set bit.

Examples

open allclose all

Basic Examples  (1)Summary of the most common use cases

Flip the initial bit of the number 2 from a 0 to a 1:

Out[1]=1

Flip the second digit of 13, counting from the right:

Out[2]=2

Flip the second digit of 13, counting form the left:

Out[3]=3

Starting with the number 0, flip positional bits:

Out[4]=4

Scope  (2)Survey of the scope of standard use cases

Digits beyond the highest set bit are implicitly set to 0:

Out[1]=1
Out[2]=2
Out[3]=3
Out[4]=4

If a flip position is given to the right of the initial set bit, the original value will be unchanged:

Out[1]=1

Properties & Relations  (2)Properties of the function, and connections to other functions

For digits that are set to 1, BitFlip is equivalent to BitClear:

Out[1]=1
Out[2]=2

For digits that are set to 0, BitFlip is equivalent to BitSet:

Out[1]=1
Out[2]=2
Wolfram Research (2024), BitFlip, Wolfram Language function, https://reference.wolfram.com/language/ref/BitFlip.html.
Wolfram Research (2024), BitFlip, Wolfram Language function, https://reference.wolfram.com/language/ref/BitFlip.html.

Text

Wolfram Research (2024), BitFlip, Wolfram Language function, https://reference.wolfram.com/language/ref/BitFlip.html.

Wolfram Research (2024), BitFlip, Wolfram Language function, https://reference.wolfram.com/language/ref/BitFlip.html.

CMS

Wolfram Language. 2024. "BitFlip." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BitFlip.html.

Wolfram Language. 2024. "BitFlip." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BitFlip.html.

APA

Wolfram Language. (2024). BitFlip. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BitFlip.html

Wolfram Language. (2024). BitFlip. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BitFlip.html

BibTeX

@misc{reference.wolfram_2025_bitflip, author="Wolfram Research", title="{BitFlip}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/BitFlip.html}", note=[Accessed: 26-March-2025 ]}

@misc{reference.wolfram_2025_bitflip, author="Wolfram Research", title="{BitFlip}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/BitFlip.html}", note=[Accessed: 26-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_bitflip, organization={Wolfram Research}, title={BitFlip}, year={2024}, url={https://reference.wolfram.com/language/ref/BitFlip.html}, note=[Accessed: 26-March-2025 ]}

@online{reference.wolfram_2025_bitflip, organization={Wolfram Research}, title={BitFlip}, year={2024}, url={https://reference.wolfram.com/language/ref/BitFlip.html}, note=[Accessed: 26-March-2025 ]}