![]() |
VOOZH | about |
The Integer.numberOfLeadingZeros(int value) method returns the number of zero bits before the first (leftmost) 1-bit in the binary representation of the given integer. If the value is 0 (i.e., no 1-bits), it returns 32.
Syntax :
public static int numberOfLeadingZeros(int arg)
Parameter: This method accepts a single parameter arg, which is the integer value.
Return Value: This method returns the number of zero bits preceding the highest-order set-bit in the two's complement binary representation of the specified int value or 32 if the value is equal to zero.
Program 1: Below programs illustrate the java.lang.Integer.numberOfLeadingZeros() method. with positive number.
Integral Number = 19 Number of Leading Zeros = 27
Explanation:
Program 2: For a negative number.
Number = -15 Number of Leading Zeros = 0
Program 3: For a decimal value.
Number of Leading Zeros = 27
Note:It returns an error message when a decimal value is passed as an argument.
Program 4: For a string value is passed in argument.
Number of Leading Zeros = 27
Note:It returns an error message when a string is passed as an argument.