D
Dale Dellutri
Is there a portable/standard way of counting the
number of bits in a variable. The following for
statement works on all the machines I've tried:
#include <stdio.h>
int main(void) {
int n;
unsigned long int a;
for (n = 0, a = 1; a != 0; a <<= 1, n++) ;
printf("unsigned long int has %d bits.\n", n);
return 0;
}
Produces:
unsigned long int has 32 bits.
I don't want to depend on C standard built-in defines.
I want to check this during program execution.
number of bits in a variable. The following for
statement works on all the machines I've tried:
#include <stdio.h>
int main(void) {
int n;
unsigned long int a;
for (n = 0, a = 1; a != 0; a <<= 1, n++) ;
printf("unsigned long int has %d bits.\n", n);
return 0;
}
Produces:
unsigned long int has 32 bits.
I don't want to depend on C standard built-in defines.
I want to check this during program execution.