-3

How to count number of bits in the variable GH that have value of 1 and assigns the results to the variable CT using while loop ?

 int main(void)
 {
      unsigned int GT = 0x12345678;
      unsigned int CT = 0;

      < The solution >

      all_done: return 0;
 }
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
MAR
  • 1

1 Answers1

0

Use bitwise shift << or >> to move a single 1 from top to bottom (or opposite), and use that as a mask to check if the corresponding bit in GT is set. Increase the counter variable if a bit is set.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621