Skip to content

Instantly share code, notes, and snippets.

@reza-ryte-club
Last active December 26, 2017 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reza-ryte-club/02034f0eb1f835c10e2feac0149d77a5 to your computer and use it in GitHub Desktop.
Save reza-ryte-club/02034f0eb1f835c10e2feac0149d77a5 to your computer and use it in GitHub Desktop.
var bitOne = 0b00000001
var maskingBit = 0b00000000
// Retrieve the state of the bit of the first digit from right side of bitOne
print(String(bitOne|maskingBit, radix: 2)) // Print 1, which indicates the first digit from the right of bitOne is 1
// Turn on the first digit of bitOne no matter what the previous bit was
bitOne = bitOne|maskingBit
// Turn off the first digit of bitOne
bitOne = bitOne&maskingBit
// Change the first digit of bitOne
maskingBit = 0b00000001
bitOne = bitOne ^ maskingBit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment