counting number of binary bits from the Long Number

Hi all, i want to know the number of binary bits in a long Number..?like sizeof the binary version of Long Number.

code:

uint32_t myNumber = 3647217053;
void setup() {
  Serial.begin(115200);
  Serial.println(myNumber, BIN);
}
void loop(){}

Hi all, i want to know the number of binary bits in a long Number.

Why?

You could use a for loop and bitRead() to see if the nth bit is set, from 0 to 31. The first one set will tell you the length.

bitRead is looking quite interesting...i want to know the number of bits as then will do some action if desired number of bits got.

then will do some action if desired number of bits got.

uint32_t myNumber = 3647217053;

if(myNumber >= (1UL << 17))
{
   //myNumber is at least 17 bits long. No need to know exactly how long it is
}

some numbers are 29 bits and some are 31 bits ..i want to have counter variable to read that ..and based on the counter value want to add 1 to the MSB ...like adding 0x80000000 if (31 bits )and adding 0x20000000 if(29 bits)...

some numbers are 29 bits and some are 31 bits

In other words, some are 31 bits and some are not. Again, the value will be greater than, or equal to, (1UL << 31) or it won't. No need to know exactly how many bits are set.

Like:

uint32_t = number = 3647217053;

uint32_t temp = number;
uint32_t addition = 1;

while(temp > 1){
  temp >>= 1;
  addition <<= 1;
}
number +=  addition;

No idea why you would like that but okay...