Skip to content

Instantly share code, notes, and snippets.

@derhuerst
Created August 21, 2015 20:45
Show Gist options
  • Save derhuerst/3165e7d2bd29ae4c0500 to your computer and use it in GitHub Desktop.
Save derhuerst/3165e7d2bd29ae4c0500 to your computer and use it in GitHub Desktop.
CoffeeScript: Set bit at offset to 0 or 1.
# offset is from the right, obviously :D
setBit = (value, offset, bit) -> ((value >> (offset+1)) << (offset+1)) | (value & (Math.pow(2, offset)-1)) | (bit << offset)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment