Binary leading zero (, binary leading zero (

Source: Internet
Author: User

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 );}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.