Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

c bits

// Setting a bit:
number |= 1 << n;

// Clearing a bit
number &= ~(1 << n);

// Toggling a bit
number ^= 1 << n;

// Checking a bit
bit = (number >> n) & 1;

// Changing the nth bit to x
number = (number & ~(1 << n)) | (x << n);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #bits
ADD COMMENT
Topic
Name
7+6 =