数字格式

发布于 2024-10-07 19:03:31 字数 397 浏览 0 评论 0原文

我正在尝试为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狼亦尘 2024-10-14 19:03:31

这些分别是 0、1 和 15 的 long 值。后缀 L 表示它是一个 long 文字,而前缀 0x 表示十六进制数字文字。

在 C# 中,您也可以做几乎相同的事情(这里不需要 L 后缀,因为编译器已经知道类型并相应地进行转换 - 在 C 代码中,定义只是字符串替换,因此类型必须随身携带):

public const long DATA_SRC_INT = 0x0;
public const long DATA_SRC_EXT = 0x1;
public const long DATA_SRC_NONE = 0xF;

但除非十六进制表示法产生实际的见解(例如位字段的组成),否则我通常坚持使用小数:

public const long DATA_SRC_INT = 0;
public const long DATA_SRC_EXT = 1;
public const long DATA_SRC_NONE = 15;

Those are long values of 0, 1 and 15, respectively. The suffixed L signals that it is a long literal, while the prefix 0x 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):

public const long DATA_SRC_INT = 0x0;
public const long DATA_SRC_EXT = 0x1;
public const long DATA_SRC_NONE = 0xF;

But unless the hexadecimal notation yields actual insights (such as composition of bit fields) I usually stick to decimals:

public const long DATA_SRC_INT = 0;
public const long DATA_SRC_EXT = 1;
public const long DATA_SRC_NONE = 15;
泪冰清 2024-10-14 19:03:31

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文