Tuesday, April 30, 2013

How to convert binary value to decimal in Java


How to convert binary to decimal in java




public static int integerfrmbinary(String str){
    double j=0;
    for(int i=0;i<str.length();i++){
        if(str.charAt(i)== '1'){
         j=j+ Math.pow(2,str.length()-1-i);
     }

    }
    return (int) j;
}


--------------------------------------------------------------------------------------

Other Way:


import java.lang.*;
import java.io.*;

public class BinaryToDecimal{
  public static void main(String[] args) throws IOException{
  BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
  System.out.print("Enter the Binary value: ");
  String str = bf.readLine();
  long num = Long.parseLong(str);
  long rem;
  while(num > 0){
  rem = num % 10;
  num = num / 10;
  if(rem != 0 && rem != 1){
  System.out.println("This is not a binary number.");
  System.out.println("Please try once again.");
  System.exit(0);
  }
  }
  int i= Integer.parseInt(str,2);
  System.out.println("Decimal:="+ i);
  }
}


run:
Enter the Binary value: 1010
Decimal:=10

--------------------------------------------

java - How to convert binary string value to decimal 
Java Convert Binary to Decimal,Binary to Decimal
How to convert binary to decimal?
Convert from binary to decimal?
HOW TO CONVERT BINARY TO DECIMAL USING JAVA PROGRAM
How do you convert a decimal number to binary in java?
How to write a java program that converts binary to 
How to write a java program to convert binary to 
Java program to convert binary,octal,decimal to 
Java Program Convert Binary to Decimal 
Decimal To Binary Converter - Java Tutorials
Binary To Decimal Conversion - Java 
Thread: Binary-to-Decimal Conversion
Searches related to java Convert Binary to Decimal
javascript convert binary decimal
java convert hexadecimal decimal
java convert binary integer
java convert binary to decimal program
java program that converts binary to decimal
decimal to binary java code
java binary string to decimal
convert a number to binary java
IT Certification Category (English)640x480

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Top Online Courses From ProgrammingKnowledge

Python Course http://bit.ly/2vsuMaS
Java Coursehttp://bit.ly/2GEfQMf
Bash Coursehttp://bit.ly/2DBVF0C
Linux Coursehttp://bit.ly/2IXuil0
C Course http://bit.ly/2GQCiD1
C++ Coursehttp://bit.ly/2V4oEVJ
PHP Coursehttp://bit.ly/2XP71WH
Android Coursehttp://bit.ly/2UHih5H
C# Coursehttp://bit.ly/2Vr7HEl
JavaFx Coursehttp://bit.ly/2XMvZWA
NodeJs Coursehttp://bit.ly/2GPg7gA
Jenkins Course http://bit.ly/2Wd4l4W
Scala Coursehttp://bit.ly/2PysyA4
Bootstrap Coursehttp://bit.ly/2DFQ2yC
MongoDB Coursehttp://bit.ly/2LaCJfP
QT C++ GUI Coursehttp://bit.ly/2vwqHSZ