-2

I need to implement this method.

I have the unsigned * x, I need to set v value in the n-th bit, using bitwise operators in C.

void set_bit(unsigned * x,
             unsigned n,
             unsigned v){

    //I need the code here, thanks for your help!
}
lurker
  • 56,987
  • 9
  • 69
  • 103
Rop
  • 3
  • 1

1 Answers1

0

Here's a macro to do that

#define SETBIT(var, bit) ((var) |= (1 << (bit)))
Stephen Docy
  • 4,738
  • 7
  • 18
  • 31