-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_decimal.cpp
More file actions
36 lines (29 loc) · 843 Bytes
/
Copy pathget_decimal.cpp
File metadata and controls
36 lines (29 loc) · 843 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
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int get_decimal(){
//Converting the hexadecimal value to decimal
char num[20] = {"B8AB"};
int hex, r, i, len = 0;
int digits[20];
len = strlen(num);
for (i = 0; num[i] != '\0'; i++){
len--;
if(num[i] >= '0' && num[i] <= '9')
r = num[i] - 48;
else if(num[i] >= 'a' && num[i] <= 'f')
r = num[i] - 87;
else if(num[i] >= 'A' && num[i] <= 'F')
r = num[i] - 55;
hex += r * pow(16,len);
}
cout<<"Decimal Value of " << num << " = " << hex << endl;
//Converting the int decimal value to an array
int number = hex;
for (int i = 0; i < 10; i++){
digits[i] = number % 10;
number = number / 10;
}
cout << digits[0];
}