将ac十六进制值转换为char*

Ren*_*ndy 1 c hex char

如何将hexc中的值转换为等效char*值.例如,如果十六进制值是1df2char*,也应该包含1df2.

我使用的VinC编译器和VinL链接器VNC2 USB ChipFTDI.它有以下头文件; stdlib,stdiostring.这些是主要c库的子集,并没有明显的答案,如snprintfsprintf.

文档说以下类型是有效的,

对于在整个内核和驱动程序中使用的变量和函数类型,存在某些定义.它们可用于vos.h头文件中的应用程序.

空指针和逻辑定义:

#define NULL                0
#define TRUE                1
#define FALSE               0
Run Code Online (Sandbox Code Playgroud)

变量类型定义:

#define uint8               unsigned char
#define int8                char
#define int16               short
#define uint16              unsigned short
#define uint32              unsigned int
#define pvoid               unsigned char *
Run Code Online (Sandbox Code Playgroud)

功能类型定义:

typedef uint8 (*PF)(uint8);
typedef void (*PF_OPEN)(void *);
typedef void (*PF_CLOSE)(void *);
typedef uint8 (*PF_IOCTL)(pvoid);
typedef uint8 (*PF_IO)(uint8 *, unsigned short, unsigned short *);
typedef void (*PF_INT)(void);
Run Code Online (Sandbox Code Playgroud)

有什么建议?

caf*_*caf 5

用途snprintf():

int to_hex(char *output, size_t len, unsigned n)
{    
    return snprintf(output, len, "%.4x", n);
}
Run Code Online (Sandbox Code Playgroud)

鉴于新信息是一个相当基本的嵌入式系统,那么如果你只对16位数字感兴趣,这样的最小解决方案可能就足够了:

/* output points to buffer of at least 5 chars */
void to_hex_16(char *output, unsigned n)
{
    static const char hex_digits[] = "0123456789abcdef";

    output[0] = hex_digits[(n >> 12) & 0xf];
    output[1] = hex_digits[(n >> 8) & 0xf];
    output[2] = hex_digits[(n >> 4) & 0xf];
    output[3] = hex_digits[n & 0xf];
    output[4] = '\0';
}
Run Code Online (Sandbox Code Playgroud)

(应该清楚如何将其扩展到更宽的数字).