string binária para int java
int decimal=Integer.parseInt(binaryString,2);
Black Bird
int decimal=Integer.parseInt(binaryString,2);
import java.util.Scanner;
class BinaryToDecimal {
public static void main(String args[]){
Scanner input = new Scanner( System.in );
System.out.print("Enter a binary number: ");
String binaryString =input.nextLine();
System.out.println("Output: "+Integer.parseInt(binaryString,2));
}
}
class Main {
public static void main(String[] args) {
// binary number
long num = 110110111;
// call method by passing the binary number
int decimal = convertBinaryToDecimal(num);
System.out.println("Binary to Decimal");
System.out.println(num + " = " + decimal);
}
public static int convertBinaryToDecimal(long num) {
int decimalNumber = 0, i = 0;
long remainder;
while (num != 0) {
remainder = num % 10;
num /= 10;
decimalNumber += remainder * Math.pow(2, i);
++i;
}
return decimalNumber;
}
}
// A program for learning and expermenting.
//not for practical use of conversion from binary to decimal
import java.util.Scanner;
class BinaryToDecimal
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("Enter a binary number:");
int n=s.nextInt();
int decimal=0,p=0;
while(n!=0)
{
decimal+=((n%10)*Math.pow(2,p));
n=n/10;
p++;
}
System.out.println(decimal);
}
}