#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned int wub_find_str_end_pt(unsigned char *str)
{
unsigned int i;
i = 0;
while (str[i] != 0x00)
i ++;
return i;
}
{
if (hex <= 9)
return hex + '0';
else
return hex - 10 + 'A';
}
void wub_str_append_byte_hex(unsigned char *str, unsigned char dat)
{
unsigned int i;
i = wub_find_str_end_pt (str);
str[i ++] = wub_hex_2_ascii (dat / 16);
str[i ++] = wub_hex_2_ascii (dat % 16);;
str[i] = 0x00;
}
unsigned int wub_hex_2_str (unsigned char *hex, unsigned char *str, unsigned int len)
{
unsigned int i;
str[0] = 0;
for (i = 0; i < len; i ++)
wub_str_append_byte_hex(str, hex[i]);
return len * 2;
}
int main()
{
char hex[255] = "\x00\x01\x09\x0A" ;
char str[255];
memset( str, 0x00, sizeof(str) );
wub_hex_2_str(hex, str, 4);
printf("str %s\n", str );
}
Output :
str 0001090A
Sekian dulu yaa :)
0 komentar:
Posting Komentar