Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

binary to decimal java






// A program for learning and expermenting.
//not for practical use of conversion from binary to decimal

import java.util.Scanner;
 
class BinaryToDecimal
{
        public static void main(String args[])
        {
            Scanner s=new Scanner(System.in);
            
            System.out.println("Enter a binary number:");
            int n=s.nextInt();
            
            int decimal=0,p=0;
            
            while(n!=0)
            {
                decimal+=((n%10)*Math.pow(2,p));
                n=n/10;
                p++;
            }
            
            System.out.println(decimal);
        }
}
Source by www.thecrazyprogrammer.com #
 
PREVIOUS NEXT
Tagged: #binary #decimal #java
ADD COMMENT
Topic
Name
1+5 =