-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoDecimal.cpp
More file actions
48 lines (38 loc) · 735 Bytes
/
toDecimal.cpp
File metadata and controls
48 lines (38 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
int BinaryToDecimal(int n){
int d=0;
int p=0;
int temp;
while(n>0){
temp = n%10;
d += (temp*(pow(2,p)));
p += 1;
n /=10;
}
return d;
}
int OctalToDecimal(int n){
int d=0;
int p=0;
int temp;
while(n>0){
temp = n%10;
d += (temp*(pow(8,p)));
p += 1;
n /= 10;
}
return d;
}
int main(){
int num1, num2;
cout<<"Enter OCtal number: \n";
cin>>num1;
cout<<"Enter Binary number: \n";
cin>>num2;
int bDecimal=BinaryToDecimal(num2);
int oDecimal = OctalToDecimal(num1);
cout<<num2<<" into Decimal: "<<bDecimal<<endl;
cout<<num1<<" into Decimal: "<<oDecimal<<endl;
return 0;
}