2

Hello is it somehow possible to set a bit flag to its real value? example

int a = 0x01 << 7

a = 128

how can I convert the 128 back to 7 ?

I tryed ^= , &= ~, &= but nothing I did worked.

Paul R
  • 208,748
  • 37
  • 389
  • 560
excuisit
  • 21
  • 1

1 Answers1

3

If you just have a single bit set then you can use a "count trailing zeroes" operation, e.g. using gcc or a gcc-compatible compiler:

int a = 128;
int bit = __builtin_ctz(a); // returns bit = 7
Paul R
  • 208,748
  • 37
  • 389
  • 560