Bit Manipulation to check if kth bit of a number is set or not

Revision en1, by CP_Sucks, 2018-12-29 20:07:24

Given Number = n To check kth bit set or not To Do 1. int temp = 1<<(k-1) (if u assume LSB to be 1 then use k-1 otherwise if assume 0 use k) 2. AND temp with n 3. If result is non-zero then set otherwise not set.

Tags bit manipulation

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English CP_Sucks 2018-12-29 20:07:24 279 Initial revision (published)