Saturday, July 22, 2023

Binary to Decimal - JAVA

 

import java.util.Scanner;

public class BinaryToDecimal {
    public static void main(String[] args) {
        int i=1,rev=0,r;
        int m,n;

        Scanner sc=new Scanner(System.in);
        System.out.println("Enter n: ");
        n=sc.nextInt();
        m=n;

        while (m>0)
        {
            r=m%2;
            rev=rev+i*r;
            m=m/2;
            i=i*10;
        }
        System.out.println("Binary = "+rev);
    }
}

No comments:

Post a Comment

Interference in Light vs Quantum States

🔬 The Double-Slit Experiment: Where It All Begins One of the most famous demonstrations of interference is the double-slit experiment. When...