summaryrefslogtreecommitdiff
path: root/2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec
diff options
context:
space:
mode:
authorsiddhu89902017-04-19 14:57:49 +0530
committersiddhu89902017-04-19 14:57:49 +0530
commitb9cfdca438347fe4d28f7caff3cb7b382e455d3a (patch)
tree948593b7d89741f804919a74f2e5e34b39adb0a0 /2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec
parent586db6343e7b472d8dc3e63a82f4c73f99cdcbd7 (diff)
downloadScilab2C-b9cfdca438347fe4d28f7caff3cb7b382e455d3a.tar.gz
Scilab2C-b9cfdca438347fe4d28f7caff3cb7b382e455d3a.tar.bz2
Scilab2C-b9cfdca438347fe4d28f7caff3cb7b382e455d3a.zip
Merged Shamik's work
Diffstat (limited to '2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec')
-rw-r--r--2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec/dbase2decs.c21
-rw-r--r--2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec/gbase2decs.c160
2 files changed, 181 insertions, 0 deletions
diff --git a/2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec/dbase2decs.c b/2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec/dbase2decs.c
new file mode 100644
index 00000000..51c42e02
--- /dev/null
+++ b/2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec/dbase2decs.c
@@ -0,0 +1,21 @@
+#include <string.h>
+#include "base2dec.h"
+#include <stdio.h>
+#include <math.h>
+
+double dbase2decs(double in,int base)
+{
+ int n=0,rem=0, base1=1;
+ double out=0.0;
+ n=(int)in;
+ while (n!=0)
+ {
+ rem = n%10;
+ out = out + (rem * base1);
+ n = n / 10 ;
+ base1 = base1 * base;
+ }
+ return out;
+}
+
+
diff --git a/2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec/gbase2decs.c b/2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec/gbase2decs.c
new file mode 100644
index 00000000..9acf2666
--- /dev/null
+++ b/2.3-1/src/c/elementaryFunctions/radix_conversions/base2dec/gbase2decs.c
@@ -0,0 +1,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;
+ }