Skip to content

Commit fe86e70

Browse files
Merge pull request #227 from AayushG02/main
added a program to convert decimal numbers to binary.
2 parents 7810850 + fcebc1e commit fe86e70

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
5+
// Decimal to binary conversion
6+
int main()
7+
{
8+
int n;
9+
cin>>n;
10+
int ans = 0;
11+
int i = 0;
12+
while(n != 0)
13+
{
14+
int bit = n&1;
15+
ans = (bit * pow(10, i)) + ans;
16+
n = n >> 1;
17+
i++;
18+
}
19+
cout<<ans;
20+
}
46.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)