将 ac 十六进制值转换为 char*
如何将 c 中的 hex
值转换为等效的 char*
值。例如,如果十六进制值为 1df2
,则 char* 还应包含 1df2
。
我正在使用来自 FTDI
的 VNC2 USB 芯片
的 VinC
编译器和 VinL
链接器。它有以下头文件; stdlib、stdio 和 字符串。然而,这些是主要 C 库的子集,没有明显的答案,例如 snprintf
或 sprintf
。
文档说以下类型是有效的,
变量和函数类型有某些定义,它们在整个内核和驱动程序中使用。它们可在 vos.h
头文件中供应用程序使用。
空指针和逻辑定义:
#define NULL 0
#define TRUE 1
#define FALSE 0
变量类型定义:
#define uint8 unsigned char
#define int8 char
#define int16 short
#define uint16 unsigned short
#define uint32 unsigned int
#define pvoid unsigned char *
函数类型定义:
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);
有什么建议吗?
How to convert a hex
value in c into an equivalent char*
value. For example if the hex value is 1df2
the char* should also contain 1df2
.
I am using the VinC
compiler and the VinL
linker for the VNC2 USB Chip
from FTDI
. It has these following header files; stdlib, stdio and string. These are however subsets of the main c libraries and don't have the obvious answers such as snprintf
or sprintf
.
The docs say the following types are valid,
There are certain definitions for variable and function types which are used throughout the kernel and drivers. They are available to applications in the vos.h
header file.
Null pointer and logic definitions:
#define NULL 0
#define TRUE 1
#define FALSE 0
Variable type definitions:
#define uint8 unsigned char
#define int8 char
#define int16 short
#define uint16 unsigned short
#define uint32 unsigned int
#define pvoid unsigned char *
Function type definitions:
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);
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
snprintf()
:鉴于新信息表明它是一个相当基本的嵌入式系统,那么如果您只对 16 位数字感兴趣,像这样的最小解决方案可能就足够了:(
应该清楚如何将其扩展到更广泛的数字)。
Use
snprintf()
:Given the new information that it's a fairly basic embedded system, then if you're only interested in 16 bit numbers a minimal solution like this probably suffices:
(It should be clear how to extend it to wider numbers).
尝试sprintf:
它比caf的答案安全性低,但如果你有stdio,应该可以工作。因此,您必须确保输出缓冲区足够大以容纳生成的字符串。
Try sprintf:
it's less safe than caf's answer but should work if you have stdio. You must therefore make sure that the output buffer is big enough to hold the resulting string.
像这样的东西应该可以做到:
但是你说你有
stdio
可用,所以不需要自己写这样的东西。编辑:可能是编译器需要 K&R 风格原型:
在 Codepad 上尝试一下。
Something like this should do it:
But you are saying you have
stdio
available, so there's no need write anything like this yourself.Edit: Could be that the compiler expects K&R style prototype:
Try this on Codepad.