Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ToDo4 {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- System.out.println("Enter binary number: ");
- int binary = s.nextInt();
- int decimal = 0;
- int power = 0;
- while (binary != 0) {
- decimal += ((binary % 10) * Math.pow(2, power));
- binary = binary / 10;
- power++;
- }
- System.out.println("Decimal number: " + decimal);
- /*
- String bin = "1010";
- int decimal2 = Integer.parseInt(bin, 2);
- System.out.println(decimal2);
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement