数字格式
我正在尝试为 C 类库创建一个 C# 包装器,用于控制 USB 数据总线通信设备。该设备支持连接到外部时钟或使用自己的内部时钟,具体取决于设备初始化时设置的值。
制造商为其 C 库提供了头文件,其中包含以下 #define 变量,
#define DATA_SRC_INT = 0x000000000L
#define DATA_SRC_EXT = 0x000000001L
#define DATA_SRC_NONE = 0x00000000FL
这给我留下了疑问。 0x000000000L
到底代表什么数字?
我意识到这个问题可能过于简单化。在我最初写这个问题时,我还没有看到大量的可移植 C 代码。我尝试根据收到的一些反馈来澄清我原来的问题。
I am attempting to create a C# wrapper for a C class library the controls an USB data bus communication device. This device supports being hooked up to an external clock or using its own internal clock depending on the value set when the device is initialized.
The manufacture provided header files for its C Library with the following #define variables
#define DATA_SRC_INT = 0x000000000L
#define DATA_SRC_EXT = 0x000000001L
#define DATA_SRC_NONE = 0x00000000FL
So that leaves me with the question. What number does 0x000000000L
represent exactly?
I realize that this question might simplistic. At the time I originally wrote this question I had not seen a great deal of portable C code. I have attempted based on some feedback I received to clarify my original question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些分别是 0、1 和 15 的
long
值。后缀L
表示它是一个long
文字,而前缀0x
表示十六进制数字文字。在 C# 中,您也可以做几乎相同的事情(这里不需要
L
后缀,因为编译器已经知道类型并相应地进行转换 - 在 C 代码中,定义只是字符串替换,因此类型必须随身携带):但除非十六进制表示法产生实际的见解(例如位字段的组成),否则我通常坚持使用小数:
Those are
long
values of 0, 1 and 15, respectively. The suffixedL
signals that it is along
literal, while the prefix0x
is for hexadecimal numeric literals.In C# you can do pretty much the same as well (the
L
suffix isn't necessary here since the compiler already knows the type and converts accordingly – in your C code the defines are only string replacements and therefore the type has to be carried with them):But unless the hexadecimal notation yields actual insights (such as composition of bit fields) I usually stick to decimals:
0x 表示该数字是十六进制的。末尾的 L 表示它很长。
所以...列出的数字分别是 0、1 和 15。
The 0x means that the number is in hex. The L at the end means that it's a long.
So... the the numbers listed are 0, 1, and 15, respectively.