Skip to content

Commit dc82c09

Browse files
committed
Added decimal to binary conversion
1 parent d6b6012 commit dc82c09

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

Decimal to Binary.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#import java.util.*;
2+
class Decimal_Binary
3+
{
4+
public static void main(String args[])
5+
{
6+
Scanner sc=new Scanner(System.in);
7+
int n,k,s=0,c=0,d;
8+
n=sc.nextInt();
9+
k=n;
10+
while(k!=0)
11+
{
12+
d=k%2;
13+
s=s+d*(int)Math.pow(10,c++);
14+
k/=2;
15+
}//converting decimal to binary
16+
System.out.println("Decimal number:"+n);
17+
System.out.println("Binary equivalent:"+s);
18+
}
19+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy