summaryrefslogtreecommitdiff
path: root/2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec/gbase2decs.c
blob: 9acf266623b6136581925ce71a3d5f0ddc71f216 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include<stdio.h>
#include<math.h>
#include "base2dec.h"
#include <string.h>

double gbase2decs(char* in,int size,int base)
{
	size-=2;
	int i=0,val=0,j=0;
	double o=0.0;
	for(i=0; in[i]!='\0'; i++)
    	{
	//printf("%c \n",in[i]);
        switch(in[i])
        {
            case '0':
                val = 0;
                break;
            case '1':
                val = 1;
                break;
            case '2':
                val = 2;
                break;
            case '3':
                val = 3;
                break;
            case '4':
                val = 4;
                break;
            case '5':
                val = 5;
                break;
            case '6':
                val = 6;
                break;
            case '7':
                val = 7;
                break;
            case '8':
                val = 8;
                break;
            case '9':
                val = 9;
                break;
            case 'a':
            case 'A':
                val = 10;
                break;
            case 'b':
            case 'B':
                val = 11;
                break;
            case 'c':
            case 'C':
                val = 12;
                break;
            case 'd':
            case 'D':
                val = 13;
                break;
            case 'e':
            case 'E':
                val = 14;
                break;
            case 'f':
            case 'F':
                val = 15;
                break;
	    case 'g':
            case 'G':
                val = 16;
                break;
	    case 'h':
            case 'H':
                val = 17;
                break;
	    case 'i':
            case 'I':
                val = 18;
                break;
	    case 'j':
            case 'J':
                val = 19;
                break;
	    case 'k':
            case 'K':
                val = 20;
                break;
	    case 'l':
            case 'L':
                val = 21;
                break;
	    case 'm':
            case 'M':
                val = 22;
                break;
	    case 'n':
            case 'N':
                val = 23;
                break;
	    case 'o':
            case 'O':
                val = 24;
                break;
	    case 'p':
            case 'P':
                val = 25;
                break;
	    case 'q':
            case 'Q':
                val = 26;
                break;
	    case 'r':
            case 'R':
                val = 27;
                break;
	    case 's':
            case 'S':
                val = 28;
                break;
	    case 't':
            case 'T':
                val = 29;
                break;
	    case 'u':
            case 'U':
                val = 30;
                break;
	    case 'v':
            case 'V':
                val = 31;
                break;
	    case 'w':
            case 'W':
                val = 32;
                break;
	    case 'x':
            case 'X':
                val = 33;
                break;
	    case 'y':
            case 'Y':
                val = 34;
                break;
	    case 'z':
            case 'Z':
                val = 35;
                break;
        }
	o = o + (val * pow(base, size));
        //printf("%f\n",out[0]);
	//o=(int)out[0];
	//o=o/16;
        //printf("%d  %d  %d\n",o,val,(val * pow(16, size)));
        //j++;
        size--;
    }
	return o;
 }