Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Flip an individual bit in an integer (0 to 1 and 1 to 0)
ResourceFunction["BitFlip"][n,p] flips the pth bit of integer n. |
Flip the 0th bit of the number 2 from a 0 to a 1:
In[1]:= | ![]() |
Out[1]= | ![]() |
Flip the 0th bit of the number 3 from a 1 to a 0:
In[2]:= | ![]() |
Out[2]= | ![]() |
Starting with the number 0, flip positional bits:
In[3]:= | ![]() |
Out[3]= | ![]() |
Flip the bit associated with 24:
In[4]:= | ![]() |
Out[5]= | ![]() |
Flip the bit associated with 27:
In[6]:= | ![]() |
Out[7]= | ![]() |
Compute the Hamming distance between a random integer and the same number with a single random bit flipped:
In[8]:= | ![]() |
Out[8]= | ![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License