Skip to content

TRUEANGLE

BEAUTY AND PLAY

  • DOLLECT
  • Others
  • Configuration
  • AI
  • BLOG
  • ABOUT
    • ABOUT
    • Perception Style

Daily Archives: June 25, 2014

How to find out if nth bit of a number is set to 1?

#include <stdio.h> int main() { int val1 = 4; int val2 = 18; int mask = 1; /* mask <<= 4; */ mask = mask << 4; printf(“mask is %d\n”,mask); if ( val1 & mask ) { printf(“Bit 5 in val1 is set\n”); } if (val2 & mask ) { printf(“Bit 5 in val2 is …

Continue reading “How to find out if nth bit of a number is set to 1?”

Posted byjeffrinJune 25, 2014Posted inC, Programming LanguagesTags: bit, hack
June 2014
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« May   Jul »
TRUEANGLE, Proudly powered by WordPress.