AJ Java Programs
Program 2:
Write a program to Convert Binary Number into a Decimal EquivalentExample: 11101 = 29
Syntax:
import java.io.*;class bintodec //binary to decimal
{
public static void main(String args[])throws IOException
{
String binary;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a biary Number");
binary=br.readLine();
int decimal=0;
int power=0;
//while(binary.length()>0)
while(binary.length()>0)
{
int temp = Integer.parseInt(binary.charAt((binary.length())-1)+"");
decimal+=temp*Math.pow(2, power++);
binary=binary.substring(0,binary.length()-1);
}
System.out.println(decimal);
}
}
Tested Ok Program
If You Don't Understand anything or want any program please write your request in Comment Section
And Please Like The Post
Comments
Post a Comment