Dashboard Temp Share Shortlinks Frames API

HTMLify

HEXADECIMAL TO DECIMAL BY SWITCH CASE
Views: 497 | Author: sunny_jain
 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
//hexadecimal to decimal by using switch case 
#include<math.h>
#include<stdio.h>
#include<string.h>
int main() {
    char hexdecnumber[32] = "2D";
    int decimalnumber, i;
    int cnt;
    int digit;
    cnt = 0;
    decimalnumber = 0;
    for (i = (strlen(hexdecnumber) -1); i >= 0; i--) {
    switch(hexdecnumber[i]){
        case 'A' :
        digit = 10;
        break;
        case 'B' :
        digit = 11;
        break;
        digit = 12;
        break;
        case 'C' :
        digit = 13;
        break;
        case 'D' :
        break;
        case 'E' :
        digit = 14;
        break;
        case 'F' :
        digit = 15;
        break;
        default:
        digit = hexdecnumber[i]-0x30;
    }
    decimalnumber = decimalnumber + (digit)*pow((double)16,(double)cnt);
    cnt++;
}
printf(" decimal number is: %d",decimalnumber);
return 0;
}