Saturday 11 November 2017

C Program to Check if nth Bit in a 32-bit Integer is Set or not


Code:

#include  stdio.h

/* gloabal varaibles */
int result,position;
/* function prototype */
int n_bit_position(int x,int position);

void main()
{
    unsigned int number;

    printf("Enter the unsigned integer:\n");
    scanf("%d", &number);
    printf("enter position\n");
    scanf("%d", &position);
    n_bit_position(i, position);
    if (result & 1)
        printf("YES\n");
    else
        printf("NO\n");
}

/* function to check whether the position is set to 1 or not */
int n_bit_position(int number,int position)
{
    result = (number>>(position));
}

Output:

Enter the unsigned integer:
101
enter position
4
NO

Enter the unsigned integer:
113
enter position
4
YES


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...