0% found this document useful (0 votes)
32 views

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

This Java program defines a Binary class to convert a binary number entered by the user to its decimal equivalent. The program takes a binary number as input, calls the convertDec method to calculate the decimal equivalent using recursion, and prints out both the binary and decimal values. It uses Math functions like pow and log to calculate each place value in binary and sum them to get the final decimal number.

Uploaded by

Bibhas Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

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

This Java program defines a Binary class to convert a binary number entered by the user to its decimal equivalent. The program takes a binary number as input, calls the convertDec method to calculate the decimal equivalent using recursion, and prints out both the binary and decimal values. It uses Math functions like pow and log to calculate each place value in binary and sum them to get the final decimal number.

Uploaded by

Bibhas Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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