"How do I find the most significant bit in an unsigned long?"
You can do shifts to the right until the last 1 is droped. In this moment, the value becomes 0.
#include <stdio.h>
int main(void) {
unsigned long x = 3333;
unsigned long y = x;
int p = -1;
while (0 != y)
p++, y >>= 1;
if (p >= 0)
printf("The most significative bit of x is at position %d\n", p);
else
printf("x is zero\n");
}