-

Fork of floathex by Javier AgroSmart

Files at this revision

API Documentation at this revision

Comitter:
agrosmart
Date:
Thu Dec 15 11:57:02 2016 +0000
Commit message:
library float2hex

Changed in this revision

floathex.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/floathex.h	Thu Dec 15 11:57:02 2016 +0000
@@ -0,0 +1,67 @@
+#include <string>
+
+string float4Hex(float value) //Deja 4 Espacios para tener en cuenta el signo, para las temperaturas
+{
+    int signo=0; // para las temperaturas
+    int ent1 =0;
+    int dec1=0;
+    char value2[5] = "0";
+
+    if(value<0) {
+        signo = 1; // 1 es negativo, 0 es positivo
+        value = value * -1;
+    } else {
+        signo = 0;
+    }
+    ent1 = value;
+    dec1 = (value - ent1)*16; //solo queda un decimal. para que queden dos decimales hay que multiplicar decimal por 10
+    sprintf(value2, "%.1X%.2X%.1X", signo, ent1,dec1); //1 de signo, 2 de entero, 1 de decimal
+    value=0;
+    return value2;
+}
+string float3dHex(float value) //Deja 3 espacios, para 2 enteros con 1 decimal
+{
+    int ent1 =0;
+    int dec1=0;
+
+    char value2[5] = "0";
+
+    ent1 = value;
+    dec1 = (value - ent1)*16;
+    sprintf(value2, "%.2X%.1X", ent1,dec1); //2 de entero, 1 de decimal
+    value=0;
+    return value2;
+}
+string float2dHex(float value) //Deja 2 espacios, para enteros con 1 decimal
+{
+    int ent1 =0;
+    int dec1=0;
+
+    char value2[5] = "0";
+
+    ent1 = value;
+    dec1 = (value - ent1)*16;
+    sprintf(value2, "%.1X%.1X", ent1,dec1); // 1 de entero, 1 de decimal
+    value=0;
+    return value2;
+}
+string float3Hex(float value) //Deja 3 espacios, para 3 enteros
+{
+    int ent1 =0;
+    char value2[5] = "0";
+
+    ent1 = value;
+    sprintf(value2, "%.3X", ent1); //3 de entero
+    value=0;
+    return value2;
+}
+string float2Hex(float value) //Deja 2 espacios, para 2 enteros 
+{
+    int ent1 =0;
+    char value2[5] = "0";
+
+    ent1 = value;
+    sprintf(value2, "%.2X", ent1); //2 de entero
+    value=0;
+    return value2;
+}
\ No newline at end of file