THIS PROGRAM HAS TO BE WRITTEN IN C
single function to count the number of leading zeroes in the 32-bit input argument passed to the function (leading zeroes are the zeroes that occur in the most significant bit positions of the number until a bit value of ‘1’ is found).
#include <stdio.h> int count_leading_zeros(unsigned int n) { int count = 0, c = 0; while (n > 0) { ++c; if (n % 2 == 1) { count = c; } n /= 2; } return 32-count; } int main() { unsigned int n = 0xFF; printf("Number of leading zeros in 0x%x is %d\n", n, count_leading_zeros(n)); n = 0xF0000000; printf("Number of leading zeros in 0x%x is %d\n", n, count_leading_zeros(n)); n = 0x00F0F0A3; printf("Number of leading zeros in 0x%x is %d\n", n, count_leading_zeros(n)); return 0; }
Get Answers For Free
Most questions answered within 1 hours.