Macro definition problem in C ? Setbit, clearbit, getbit

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Strange behaviour with my macros.
When I set bit 1, getbit returns a 128.
Than I clear bit 1 and getbit returns 254.

Is there anything wrong with those macros ?

#define SETBIT(x,n) ((x)|=1L<<(n))
#define CLEARBIT(x,n) ((x)&=~(1L<<(n)))
#define GETBIT(x,n) ((x)&1L<<(n))

thanks in advance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

They are OK. I probably wouldn't write 1L, but that depends on your
application.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Jörg.

I will try it without the "1L" or the problem is somewhere else to look for.

Harald.