20120113

Program in C to set nth bit, bitset.c

//========================
//Program in C to set nth bit, bitset.c
//========================
#include<stdio.h>
int showbits(int nn)
{
unsigned int m;
m=1<<(sizeof(nn)*8-1);
        while(m > 0)
        {
                if(nn & m)
                {
                printf("1");
                }
                else
                {
                printf("0");
                }
        m>>=1;
        }
}
int main()
{
int number,bits;
printf("Enter a nomber and bits to set:\n");
scanf("%d%d",&number,&bits);
printf("\n You Entered: %d and %d  \n",number,bits);
showbits(number);
number=number^(1<<(bits-1));
printf("\n Number now is: %d \n",number);
showbits(number);
printf("\n");
return 0;
}

4 comments:

  1. Program in CPP/C++ to set nth bit, bitset.c
    Program in CPP/C++ to set nth bit, bitset.c
    Program in CPP/C++ to set nth bit, bitset.c
    Program in CPP/C++ to set nth bit, bitset.c
    Program in CPP/C++ to set nth bit, bitset.c Program in CPP/C++ to set nth bit, bitset.c
    Program in CPP/C++ to set nth bit, bitset.c

    ReplyDelete
    Replies
    1. Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c

      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c

      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c

      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c

      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c Program in CPP/C++ to set nth bit, bitset.c
      Program in CPP/C++ to set nth bit, bitset.c

      Delete
  2. Program in CPP/C++ to set nth bit, bitset.c
    Program in CPP/C++ to set nth bit, bitset.c
    Program in CPP/C++ to set nth bit, bitset.c Program in CPP/C++ to set nth bit, bitset.c
    Program in CPP/C++ to set nth bit, bitset.c

    ReplyDelete
  3. Program in CPP/C++ to set nth bit, bitset.c
    Program in CPP/C++ to set nth bit, bitset.c
    Program in CPP/C++ to set nth bit, bitset.c Program in CPP/C++ to set nth bit, bitset.c

    ReplyDelete