summaryrefslogtreecommitdiff
path: root/src/c/elementaryFunctions/radix_conversions/hex2dec
diff options
context:
space:
mode:
authorsiddhu89902017-04-19 14:57:49 +0530
committersiddhu89902017-04-19 14:57:49 +0530
commit1fd0dce8d72c4d5869ce5ff4025ac09af603bc0f (patch)
tree34e52b33707a829c1d8484428c96d3f1f6ce2b3a /src/c/elementaryFunctions/radix_conversions/hex2dec
parent9e506f48291533cba7b4c555b0d2e98f234bfbe3 (diff)
downloadScilab2C_fossee_old-1fd0dce8d72c4d5869ce5ff4025ac09af603bc0f.tar.gz
Scilab2C_fossee_old-1fd0dce8d72c4d5869ce5ff4025ac09af603bc0f.tar.bz2
Scilab2C_fossee_old-1fd0dce8d72c4d5869ce5ff4025ac09af603bc0f.zip
Merged Shamik's work
Diffstat (limited to 'src/c/elementaryFunctions/radix_conversions/hex2dec')
-rw-r--r--src/c/elementaryFunctions/radix_conversions/hex2dec/dhex2decs.c21
-rw-r--r--src/c/elementaryFunctions/radix_conversions/hex2dec/ghex2decs.c81
2 files changed, 102 insertions, 0 deletions
diff --git a/src/c/elementaryFunctions/radix_conversions/hex2dec/dhex2decs.c b/src/c/elementaryFunctions/radix_conversions/hex2dec/dhex2decs.c
new file mode 100644
index 0000000..cfe0594
--- /dev/null
+++ b/src/c/elementaryFunctions/radix_conversions/hex2dec/dhex2decs.c
@@ -0,0 +1,21 @@
+#include <string.h>
+#include "hex2dec.h"
+#include <stdio.h>
+#include <math.h>
+
+double dhex2decs(double in)
+{
+ int n=0,rem=0, base=1;
+ double out=0.0;
+ n=(int)in;
+ while (n!=0)
+ {
+ rem = n%10;
+ out = out + (rem * base);
+ n = n / 10 ;
+ base = base * 16;
+ }
+ return out;
+}
+
+
diff --git a/src/c/elementaryFunctions/radix_conversions/hex2dec/ghex2decs.c b/src/c/elementaryFunctions/radix_conversions/hex2dec/ghex2decs.c
new file mode 100644
index 0000000..c5b68db
--- /dev/null
+++ b/src/c/elementaryFunctions/radix_conversions/hex2dec/ghex2decs.c
@@ -0,0 +1,81 @@
+#include <string.h>
+#include "hex2dec.h"
+#include <stdio.h>
+#include <math.h>
+
+double ghex2decs(char* in,int size)
+{
+ size-=2;
+ int i=0,val=0,j=0;
+ double o=0.0;
+ for(i=0; in[i]!='\0'; i++)
+ {
+/* Finds the decimal equivalent of each hexadecimal digit
+*/
+ 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;
+ }
+ o = o + (val * pow(16, 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;
+ }