Binary

import java.util.*; public class binary { public binary() { Scanner reader = new Scanner(System.in); // Reading from System.in System.out.println("Please Enter a binary"); String input = reader.next(); int count = 0; int degree = input.length()-1; for(int i = 0; i < input.length(); i++){ count += Integer.parseInt(input.substring(i,i+1)) * (Math.pow(2,degree)); degree --; } System.out.println("decimal : " + count); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.