0

I have three 32 bit integers a,b,c. I want to make 10th bit of a=(23 rd bit of b) xor (4th bit of c) without disturbing other bits of a. How can I do this in C programming language? a can be zero also. In that case I consider a= 00...0, 32 zeros.

user12290
  • 275
  • 2
  • 6

1 Answers1

1
// 10th bit of a=(23 rd bit of b) xor (4th bit of c)

if( a )
{ // skip if 'a' already all 0's
    int tempB = (b>>23)&0x01; // extract bit 23 and place on bit 0
    int tempC = (c>>4)&0x01;  // extract bit 4 and place in bit 0
    int tempXOR = (tempB^tempC)&0x01;// XOR the bits

    a &= ~(1<<10);        // clear bit 10
    a |= (tempXOR<<10);   // place result of XOR into bit 10 of a
}
user3629249
  • 126
  • 2