({{, (RefLink[BitSet, paclet:ref/BitSet])[n,k] 
sets to 1 the bit corresponding to the coefficient of (2^k) in the integer n. }})

OpenersNotesSection(Spacer1)Details

(RefLink[BitSet, paclet:ref/BitSet])[n,k] sets the bit k places from the right.

OpenersPrimaryExamplesSection(Spacer1)Examples  (2)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Display coefficients at powers of 2 in the integer 42:

IntegerDigits[42,2]

Set the bit corresponding to the coefficient at (2^0) to 1:

BitSet[42,0]

IntegerDigits[%,2]

Set the bit corresponding to the coefficient at (2^4):

BitSet[42,4]

IntegerDigits[%,2]

OpenersExampleSection1(Spacer1)Scope  (1)

(RefLink[BitSet, paclet:ref/BitSet]) automatically creates an integer of the necessary size:

IntegerDigits[42,2]

BitSet[42,9]

IntegerDigits[%,2]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[BitClear, paclet:ref/BitClear])  ▪  (RefLink[BitGet, paclet:ref/BitGet])  ▪  (RefLink[BitLength, paclet:ref/BitLength])  ▪  (RefLink[BitOr, paclet:ref/BitOr])  ▪  (RefLink[ReplacePart, paclet:ref/ReplacePart])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Integer and Number Theoretic Functions, paclet:tutorial/IntegerAndNumberTheoreticalFunctions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Bitwise Operations, paclet:guide/BitwiseOperations])}, {▪(RefLinkPlain[Boolean Computation, paclet:guide/BooleanComputation])}, {▪(RefLinkPlain[Number Digits, paclet:guide/NumberDigits])}, {▪(RefLinkPlain[Integer Functions, paclet:guide/IntegerFunctions])}, {▪(RefLinkPlain[Cryptographic Number Theory, paclet:guide/CryptographicNumberTheory])}})}})