这ç数据类型可以重新present一个40位二进制数? [英] Which C datatype can represent a 40-bit binary number?
问题描述
我需要重新present一个40位二进制数。这ç数据类型应该用于处理?
I need to represent a 40-bit binary number. Which C datatype should be used to handle this?
推荐答案
如果您使用的是C99或C11兼容的编译器,然后用 int_least64_t
的最大兼容性。或者,如果你想要一个无符号的类型, uint_least64_t
。这些都是在这两个定义的< stdint.h>
If you're using a C99 or C11 compliant compiler, then use int_least64_t
for maximum compatibility. Or, if you want an unsigned type, uint_least64_t
. These are both defined in <stdint.h>
&LT; stdint.h&GT;
通常还定义的int64_t
,但因为它不是由标准的要求,但可能不会在每一个实施进行定义。但是:
<stdint.h>
usually also defines int64_t
, but since it's not required by the standard, it may not be defined in every implementation. However:
-
int_least64_t
- 至少有64位,和 -
int_fast64_t
- 在此实现至少有64位最快尺寸
int_least64_t
- at least 64 bits, andint_fast64_t
- the fastest size in this implementation of at least 64 bits
都要求在C99和C11 present(见C99标准§7.18.1.2-3,并在C11标准§7.20.1.2-3)。
are both required to be present in C99 and C11 (See § 7.18.1.2-3 in the C99 standard, and § 7.20.1.2-3 in the C11 standard).
虽然C99指定长长
至少在一个特定的机(第5.2.4.2.1)64位,在 &LT; stdint.h方式&gt;
被设计成便携式明确
Although C99 specifies that long long
is at least 64 bits on a particular machine (§ 5.2.4.2.1), the types in <stdint.h>
are designed to be explicitly portable.
您可以阅读更多关于整数大小不同的平台上这里。
需要注意的是整数类型的大小都与长
数据类型的问题 - 在64位的Windows,这是目前32位,而在64位Linux是64位。出于这个原因,我相信你是最安全的使用类型从&LT; stdint.h&GT;
You can read more about integer sizes on different platforms here.
Note that the size of integer types are a problem with the long
data type - on 64 bit Windows, it's currently 32 bits, whereas on 64 bit linux it's 64 bits. For this reason, I believe you're safest using the types from <stdint.h>
这是值得注意的是,有些人觉得长长
更具有可读性。就个人而言,我preFER从&LT的类型; stdint.h&GT;
,因为他们让你说你是什么意思时,你使用它们 - 我觉得这更易读。当然,可读性往往是口味的问题 - 如果你使用现有的codeBase的工作,我只是跟着无论他们做什么:)
It's worth noting that some feel that long long
is more readable. Personally, I prefer the types from <stdint.h>
, because they allow you to say what you mean when you use them - which I find more readable. Of course, readability is often a matter of taste - and if you're working with an existing codebase, I'd just follow whatever they do :)
如果你的编译器只支持C89,那么<一个href=\"http://stackoverflow.com/questions/9595225/which-c-datatype-can-re$p$psent-a-40-bit-binary-number/9596246#9596246\">R..'s解决方案将让你到整数precision的53位。
If your compiler only supports C89, then R..'s solution will allow you up to 53 bits of integer precision.
这篇关于这ç数据类型可以重新present一个40位二进制数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!