build system revision
[vg.git] / vg_binstr.c
diff --git a/vg_binstr.c b/vg_binstr.c
new file mode 100644 (file)
index 0000000..7d9ac83
--- /dev/null
@@ -0,0 +1,23 @@
+#include "vg/vg_binstr.h"
+
+void vg_str_bin( const void *txt, void *bin, int size )
+{
+   const u8 *src = txt;
+         u8 *dst = bin;
+
+   for( u32 i=0; i<size/2; i++ ){
+      dst[i]  = (src[i*2+0]-VG_BINSTR_BASECHAR);
+      dst[i] |= (src[i*2+1]-VG_BINSTR_BASECHAR)<<4u;
+   }
+}
+
+void vg_bin_str( const void *bin, void *txt, u32 size )
+{
+         u8 *dst = txt;
+   const u8 *src = bin;
+
+   for( u32 i=0; i<size; i++ ){
+      dst[i*2+0] = VG_BINSTR_BASECHAR + ((src[i]    ) & 0xf);
+      dst[i*2+1] = VG_BINSTR_BASECHAR + ((src[i]>>4u) & 0xf);
+   }
+}