Q:

C Program to check whether all bits of a number are UNSET/LOW?

0

C Program to check whether all bits of a number are UNSET/LOW?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>


int isAllBitsUnset(unsigned int num)
{
    int loop, cnt=0;
    
    for(loop=7; loop>=0; loop--)
    {
        
        if( num & (1<<loop))
        {
            cnt =1;
            break;
        }
    }
    if(cnt==0)
        return 1; //true
    else
        return 0; //false
}


int main()
{
    unsigned int number;
    
   
    printf("Enter an integer number (between 0-255): ");
    scanf("%d",&number);
    
    if(isAllBitsUnset(number))
        printf("All bits are UNSET/LOW.\n");
    else
        printf("All bits are not UNSET/LOW.\n");
        
    return 0;   
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now