in reply to Detecting whether UV fits into an NV

Here's a hastily thrown together short program that does all the work. Removes trailing zeros, counts the number of bits remaining in the number, and informs you whether the number fits within 53 bits.

#include <stdio.h> #include <stdint.h> #include <math.h> #define MAXLEN 53 unsigned int bitCount(unsigned long num); uint8_t doesItFit(unsigned long num); void main () { int num = 0b10100000; unsigned long bigNum = 18446744073709551615; // 2^64-1 printf( "Fit? Small: %d, Big: %d\n", doesItFit(num), doesItFit(bigNum) ); } unsigned int bitCount(unsigned long num) { unsigned int bits = 0; while (num) { bits++; num >>= 1; } return bits; } uint8_t doesItFit (unsigned long num) { num = num >> __builtin_ctz(num); unsigned int numBits = bitCount(num); return numBits <= MAXLEN ? 1 : 0; }

Output:

Fit? Small: 1, Big: 0