#include <stdio.h>
#include <math.h>
/**
* Rounds an unsigned integer down to the previous power of 2.
*
* return the previous power of 2 less than or equal to n
*/
unsigned int roundToPreviousPowerOf2(unsigned int n) {
if (n == 0) return 0;
return (unsigned int)pow(2, floor(log2(n)));
}
int main() {
unsigned int num = 31;
printf("Previous power of 2: %u\n", roundToPreviousPowerOf2(num));
return 0;
}
/*
run:
Previous power of 2: 16
*/