#include <stdio.h>

int main(){
    int a = 10; //1010
    
    a = a | (1<<0);
    printf("%d\n",a);
    
    a = a & ~(1<<0);
    printf("%d\n",a);
    
    a = a ^ (1<<0);
    printf("%d\n",a);
    
    if(a&(1<<0)){
        printf("Its 1\n");
    }
    else{
        printf("Its 0\n");
    }
    
    int count = 0;
    while (a) {
        if (a & (1<<0)) {//or (a & 1)
            count++;
        }
        a = a >> 1; // Right shift a by 1 bit
    }
    /*
    Note: The while loop now includes a >>= 1; statement, which performs a
    right shift operation on a by 1 bit in each iteration. This shift is 
    necessary to check all the bits in a until it becomes 0 */
    
    printf("Number of set bits: %d\n", count);
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: