Binary leading zero (, binary leading zero (
Binary leading zero
Subject content:
The computer uses binary to express all values. A decimal number, for example, 18, is expressed as 00000000000000000000000000011000 in a 32-bit computer. We can see that there are 27 0 numbers before the first 1 from the left. We call these zeros the leading zeros.
Now, your task is to write a program, input an integer, and output the number of leading zeros in the 32-bit binary expression.
Input Format:
An integer within the range that can be expressed by a 32-bit integer.
Output Format:
An integer that represents the number of zeros before the first 1 when the input is expressed as a 32-bit binary number.
Input example:
256
Output example:
23
Import java. util. extends; public class Main {public static void main (String [] args) {Using SC = new using (System. in); int number = 0; // an integer within a 32-bit integer can be expressed. Int wei = 32; // 32-bit computer String result = null; // String number = SC. nextInt (); // enter result = Integer. toBinaryString (number); // Returns a string representation of the integer argument as an unsigned integer in base 2.if (number! = 0) {// an integer that represents the number of zeros before the first 1 when the input is expressed as a 32-bit binary number. System. out. println (wei-result. length ();} else {System. out. println (wei );}}}