Mathematica > Mathematics and Algorithms > Discrete Mathematics > Boolean Computation > Bitwise Operations >
Mathematica > Mathematics and Algorithms > Logic & Boolean Algebra > Boolean Computation > Bitwise Operations >

BitSet

BitSet[n, k]
sets to 1 the bit corresponding to the coefficient of 2^k in the integer n.
  • BitSet[n, k] sets the bit k places from the right.
Display coefficients at powers of 2 in the integer 42:
In[1]:=
Click for copyable input
Out[1]=
Set the bit corresponding to the coefficient at 20 to 1:
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
Set the bit corresponding to the coefficient at 24:
In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input
Out[5]=
New in 6
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team