for example,if i have number 64,then its binary representation would be 0000 0000 0000 0000 0000 0000 0100 0000 so leading number of zero\'s is 25. remember i have to calculate
Right shift is your friend.
int input = 64; int sample = ( input < 0 ) ? 0 : input; int leadingZeros = ( input < 0 ) ? 0 : 32; while(sample) { sample >>= 1; --leadingZeros; } printf("Input = %d, leading zeroes = %d\n",input, leadingZeros);