English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

You need to go read up on bitwise operators. It isn't hard if you find the right chapter in your C book. I'd tell you more but I don't program in C and I don't deal with such issues.

2006-10-29 01:15:00 · answer #1 · answered by Anonymous · 2 0

int a = 12; // binary 1100
int b = a ^ 2; // 1100 XOR 0010 = 1110
int c = a & 3; // 1100 AND 0011 = 0000
int d = a | 1; // 1100 OR 0001 = 1101


// if you do a check to see if the second bit is on or off
// and switch you could do this
if ( a & 2 ) a ^= 2; else a ^= 2;

// of course you could just not check and switch anyway
a ^=2;

2006-10-29 04:52:15 · answer #2 · answered by Daniel H 5 · 1 0

This is the program to shuffle any given bit in a number.

#include
#include
#include

void main()
{
int number,bitToShuffle;
clrscr();
printf("Enter the Number ");
scanf("%d",&number);
printf("Enter the bit to be shuffled ");
scanf("%d",&bitToShuffle);

printf("%d", (number^(int)pow(2,bitToShuffle-1)));

getch();

}

2006-10-30 16:00:19 · answer #3 · answered by manoj Ransing 3 · 0 0

fedest.com, questions and answers