[Introduction to programming in Java note] 1.3.7 converting to binary decimal to binary conversion

Source: Internet
Author: User
Tags decimal to binary

 Public classbinary{ Public Static voidMain (string[] args) {//Print binary representation of N.        intN = Integer.parseint (args[0]); intv = 1;  while(v <= N/2) v=v; //Now V is the largest power of 2 <= N.        intn = n;//Current Excess         while(V > 0)        { //Cast out the power of 2 in decreasing order.            if(N < v) {System.out.print (0); }            Else{System.out.print (1); n-=v;} V= V/2;    } System.out.println (); }}
Prints a binary representation of a 10-decimal number. Splits a number into the sum of a power of 2. For example 19 = 16 + 2 + 1. So the binary representation of 19 is 10011.  

  

[Introduction to programming in Java note] 1.3.7 converting to binary decimal to binary conversion

Related Article

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.