Dec 23, 2010

Binary to Decimal in Java

Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class BinarytoDecimal {

    public static void main(String[] argsthrows Exception {
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the binary value:");
         String binary = br.readLine();
        System.out.println("Decimal value is : "+Integer.parseInt(binary,2));

    }
}
Output:


Enter the binary value: 110
Decimal value is : 6

No comments:

Post a Comment

Post a Comment

Note: Only a member of this blog may post a comment.