Class Binary - ISC COMPUTER PROJECT 2018: Import Class Long Void

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Class Binary - ISC COMPUTER PROJECT 2018 1/1

1 import java.util.*;
2 class Binary
3 {
4 long bin,dec;
5
6 void readBin()
7 {
8 Scanner sc=new Scanner(System.in);
9 System.out.print("ENTER A BINARY NUMBER: ");
10 bin=sc.nextLong();
11 }
12
13 long convertDec(long num)
14 {
15 int dig=(int)Math.log10(num)+1;
16 if(dig==1)
17 {
18 return num;
19 }
20 else
21 {
22 return (long)(Math.pow(2,dig-1)+convertDec(num%(long)(Math
.pow(10,dig-1))));
23 }
24 }
25
26 void Show()
27 {
28 System.out.println("THE BINARY NUMBER IS: "+bin);
29 System.out.println("THE DECIMAL EQUIVALENT IS: "+ convertDec(b
in));
30 }
31
32 public static void main(String args[])
33 {
34 Binary obj=new Binary();
35 obj.readBin();
36 obj.Show();
37 }
38 }
39

5 Aug, 2017 10:03:23 PM

You might also like