Saturday 11 November 2017

C Program to Check if a given Bit Position is set to One or not


Code:

#include stdio.h

void main()
{
    unsigned int number;
    int result, position;

    printf("Enter the unsigned integer:\n");
    scanf("%d", &number);
    printf("enter position to be searched\n");
    scanf("%d", &position);
    result = (number >> (position));
    if (result & 1)
        printf("TRUE\n");
    else
        printf("FALSE\n");    
}


Output:

Enter the unsigned integer:
128
enter position to be searched
7
TRUE


More C Programs:












100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...