二进制重新$ P $一个.NET小数的psentation [英] Binary representation of a .NET Decimal

查看:141
本文介绍了二进制重新$ P $一个.NET小数的psentation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,快速的问题:如何做一个.NET 十进制键入得到psented二进制在内存中再$ P $?

Hey all, quick question: How does a .NET decimal type get represented in binary in memory?

我们都知道浮点数存储和正是如此的原因,其不准确,但我无法找到十进制除以下的信息:

We all know how floating-point numbers are stored and the thusly the reasons for the inaccuracy thereof, but I can't find any information about decimal except the following:

  1. 显然比浮点数更精确
  2. 采用128位的内存
  3. 2 ^ 96 +符号范围
  4. 28(有时29?)的数量总显著位数

有什么办法,我可以想出解决办法?在我的计算机科学家需要的答案,并试图研究一个小时后,我找不到它。好像有任何浪费许多位或者我只是想象这个错误在我的脑海。任何人都可以提供一些线索对这个好吗?谢谢你。

Is there any way I can figure this out? The computer scientist in me demands the answer and after an hour of attempted research, I cannot find it. It seems like there's either a lot of wasted bits or I'm just picturing this wrong in my head. Can anyone shed some light on this please? Thanks.

推荐答案

<一个href="http://msdn.microsoft.com/en-us/library/system.decimal.getbits.aspx"><$c$c>Decimal.GetBits对于信息你想要的。

Decimal.GetBits for the information you want.

基本上它是一个96位整数的尾数,再加上一个符号位,再加上一个指数,以说有多少的十进制的地方将它转移到右侧。

Basically it's a 96 bit integer as the mantissa, plus a sign bit, plus an exponent to say how many decimal places to shift it to the right.

因此​​,要重新present 3.261你有3261尾数,0(即正)符号位,和3。需要注意的是十进制的指数是不归(故意),这样你就可以的重新present 3.2610通过使用32610尾数和4的指数,例如

So to represent 3.261 you'd have a mantissa of 3261, a sign bit of 0 (i.e. positive), and an exponent of 3. Note that decimal isn't normalized (deliberately) so you can also represent 3.2610 by using a mantissa of 32610 and an exponent of 4, for example.

我在我的十进制浮点文章更多的信息。

I have some more information in my article on decimal floating point.

这篇关于二进制重新$ P $一个.NET小数的psentation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆