Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

binary string to int java

int decimal=Integer.parseInt(binaryString,2);
Comment

binary to integer in java

System.out.println(Integer.parseInt("1010",2));  
Comment

Binary to Decimal Conversion in java

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;
  }
}
Comment

binary to decimal in java program

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));
    }
}
Comment

binary to int java

int foo = Integer.parseInt("1001", 2); // 2 is the radix
Comment

binary to decimal java






// 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);
        }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java collection to list 
Java :: java calendar hour vs hour of day 
Java :: how to convert arraylist to array in java 
Java :: java get variable from another class 
Java :: pi in java 
Java :: como calcular a raiz quadrada em java 
Java :: java random uuid 
Java :: what it means when create final variable in java 
Java :: java do something after x seconds without stopping everything else 
Java :: groovy ternary operator short form 
Java :: android localdatetime 
Java :: android check if app is running 
Java :: java convert string to int array 
Java :: how to compare current date and time with another date and time in android 
Java :: check if string contains only letters java 
Java :: how to add animation between activity in android 
Java :: java parse unix timestamp 
Java :: java setbounds 
Java :: write input stream to file java 
Java :: check if number is odd java 
Java :: how to add input in array java 
Java :: java stream limit items 
Java :: Islands count leetcode 
Java :: how to convert string array to int in java 
Java :: String remove duplicate in java 
Java :: string to char in java 
Java :: java protected 
Java :: java copy file 
Java :: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin 
Java :: random in java a to b 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =