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

Complete Works of Swami Vivekananda [Volume 8,Page - 2069]

  Complete Works of Swami Vivekananda [ Volume 8, Page - 2069] Jesus Christ was God — the Personal God become man. He has manifested Himsel...