-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhex2str.c
More file actions
31 lines (28 loc) · 744 Bytes
/
Copy pathhex2str.c
File metadata and controls
31 lines (28 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <stdint.h>
char hexStr[256];
void hex2str(char *data, uint8_t data_len)
{
unsigned char * pin = data;
const char * hex = "0123456789ABCDEF";
char * pout = hexStr;
uint8_t i = 0;
for(; i < data_len- 1; ++i)
{
*pout++ = hex[(*pin>>4)&0xF];
*pout++ = hex[(*pin++)&0xF];
}
*pout++ = hex[(*pin>>4)&0xF];
*pout++ = hex[(*pin)&0xF];
pout = hexStr;
printf("%s",pout);
}
int main()
{
char data[] ={0x97,0x31,0x30,0x31,0x30,0x31};
hex2str(data,6);
// const char * hex = "0123456789ABCDEF";
// char data1[] = {hex[(0x97>>4) & 0x0F],hex[(0x97) & 0x0F]};
// printf(" %s",data1);
return 0;
}