#include <stdio.h>
template< typename IntType >
int numberOfBits() {
IntType newValue = 1;
IntType oldValue = 0;
int numBits = 0;
while(oldValue != newValue) {
++numBits;
oldValue = newValue;
newValue = (newValue << 1) + 1;
}
return numBits;
}
int main(int argc, char* argv[]) {
printf("sizeof(int) : %d\n", sizeof(int) * 8);
printf("size of <int>: %d\n", numberOfBits<int>());
printf("\n");
printf("sizeof(unsigned int) : %d\n", sizeof(unsigned int) * 8);
printf("size of <unsigned int>: %d\n", numberOfBits<unsigned int>());
printf("\n");
printf("sizeof(short) : %d\n", sizeof(short) * 8);
printf("size of <short>: %d\n", numberOfBits<short>());
return 0;
}
|