“Binary to desimal Java” Kode Jawaban

string biner ke int java

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

biner ke desimal dalam program java

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));
    }
}
Cute Capuchin

Biner ke konversi desimal di 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;
  }
}
Different Dragonfly

Binary to desimal 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);
        }
}
Delightful Dogfish

Jawaban yang mirip dengan “Binary to desimal Java”

Pertanyaan yang mirip dengan “Binary to desimal Java”

Lebih banyak jawaban terkait untuk “Binary to desimal Java” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya