Skip to content

Commit 2ddcc4e

Browse files
authored
Add files via upload
1 parent c7a3126 commit 2ddcc4e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Hacker Blocks/Binary To Decimal.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Hacker Blocks */
2+
/* Title - Binary To Decimal */
3+
//Take N (number in binary format). Write a function that converts it to decimal format and Print the value returned.
4+
5+
#include<iostream>
6+
#include<cmath>
7+
using namespace std;
8+
int convert(int num)
9+
{
10+
int count = 0;
11+
int sum =0;
12+
int temp;
13+
while(num>0)
14+
{
15+
temp = (num%10)*pow(2,count++);
16+
sum += temp;
17+
num /= 10;
18+
}
19+
return sum;
20+
}
21+
int main() {
22+
int n,num;
23+
cin>>n;
24+
num = convert(n);
25+
cout<<num<<endl;
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)