diff --git a/September/19-09-2023_Find first set bit b/September/19-09-2023_Find first set bit new file mode 100644 index 0000000..8199e88 --- /dev/null +++ b/September/19-09-2023_Find first set bit @@ -0,0 +1,17 @@ +class Solution +{ + public: + //Function to find position of first set bit in the given number. + unsigned int getFirstSetBit(int n) + { + unsigned int cnt=1; + while(n>0){ + if(n&1){ + return cnt; + } + n = n>>1; + cnt++; + } + return 0; + } +};