C# 32 位和 64 位操作系统中的双字节大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1101463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 08:15:19  来源:igfitidea点击:

The Double Byte Size in 32 bit and 64 bit OS

c#64-bitfloating-pointdoubleieee-754

提问by Graviton

Is there a difference in doublesize when I run my app on 32 and 64 bit environment?

当我在 32 位和 64 位环境中运行我的应用程序时,双倍大小有区别吗?

If I am not mistaken the double in 32 bit environment will take up 16 digits after 0, whereas the double in 64 bit will take up 32 bit, am I right?

如果我没记错的话,32位环境下的double会占用0后的16位,而64位环境下的double会占用32位,对吗?

采纳答案by John Kugelman

No, an IEEE 754 double-precision floating point numberis always 64 bits. Similarly, a single-precision floatis always 32 bits.

不,IEEE 754 双精度浮点数始终是 64 位。同样,单精度float始终是 32 位。

If your question is about C# and/or .NET specifically (as your tag would indicate), allof the data type sizes are fixed, independent of your system architecture. This is the same as Java, but different from C and C++ where type sizes do vary from platform to platform.

如果您的问题特别是关于 C# 和/或 .NET(如您的标签所示),则所有数据类型大小都是固定的,与您的系统架构无关。这与 Java 相同,但与 C 和 C++ 不同,其中类型大小因平台而异。

It is common for the integral types to have different sizes on different architectures in C and C++. For instance, intwas 16 bits wide in 16-bit DOS and 32 bits wide in Win32. However, the IEEE 754 standard is so ubiquitous for floating-point computation that the sizes of floatand doubledo notvary on any system you will find in the real world--20 years ago doublewas 64 bits and so it is today.

整数类型在 C 和 C++ 中的不同体系结构上具有不同的大小是很常见的。例如,int在 16 位 DOS 中为 16 位宽,在 Win32 中为 32 位宽。然而,IEEE 754 标准在浮点计算中无处不在,以至于您在现实世界中会发现的任何系统上的大小float和大小double不会改变——20 年前double是 64 位,今天也是。

回答by Learner

In c# double is always 8 bytes (64 bits)

在 c# 中 double 总是 8 字节(64 位)

回答by statenjason

It doesn't change.

它不会改变。

A simple way to check for this is writing a simple console app with

检查此问题的一种简单方法是编写一个简单的控制台应用程序

Console.WriteLine(Double.MaxValue);

and compiling to both x86 and x64.

并编译为 x86 和 x64。