Re: Decimal Data Type bit layout



The exact lay-out in BCL

32 bit flags
32 bit word high
32 bit word low
32 bit word mid
So 96 bits representing the number.

flags represent the scale and the sign, as follows:

31----24 - sign - number is negative when bit 31 = 1 (only one bit used)
23----16 - scale bits - number of decimal places (valid range 0-28, 5 bits
used)
fi. 12.365 is represented a 12365 with scale 3
remaining bits of flags are not used.


Willy.






"mdavidjohnson" <mdj@xxxxxxxxxxxxx> wrote in message
news:782F5053-58FA-4206-BD72-110AA28342A7@xxxxxxxxxxxxxxxx
> Sorry, I meant 11-bit exponent (I've got floats, doubles, and decimals all
> swirling around in my head at the moment)
>
> "Jon Skeet [C# MVP]" wrote:
>
>> mdavidjohnson <mdj@xxxxxxxxxxxxx> wrote:
>> > What is the actual bit layout of the decimal data type?
>> >
>> > i.e.; if the double data type layout is sign = 1 bit, biased exponent =
>> > 11
>> > bits, and mantissa = 52 bits; what is the corresponding description for
>> > decimal?
>> >
>> > I read that a decimal includes a 1-bit sign, a 96-bit integer number,
>> > and an
>> > exponent that ranges from 0 to 28 (which would require 5 bits). The
>> > total
>> > would thus be 102 bits which would fit in 13 bytes with two bits left
>> > over.
>> > Seems strange.
>>
>> That's exactly the layout - if you look at the docs for Decimal, it's
>> documented there.
>>
>> I suspect the reason it doesn't go any further is that it's a lot
>> easier (and quicker) to manipulate three ints as the mantissa than
>> "three and a bit" ints. I suspect there aren't many applications for
>> which 28 digits is insufficient, but a couple more digits would be
>> okay.
>>
>> --
>> Jon Skeet - <skeet@xxxxxxxxx>
>> http://www.pobox.com/~skeet
>> If replying to the group, please do not mail me too
>>


.



Relevant Pages

  • Re: Decimal Data Type bit layout
    ... > flags represent the scale and the sign, ... The third edition of the Ecma standard for CLI does not specify ... conceivable that Microsoft will adopt this representation at some ... externally stored decimals should be ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Comparing float and decimal
    ... Mark Dickinson wrote: ... and Decimals by keeping flags in each set indicating ...
    (comp.lang.python)
  • Problem display of number in calculate-field
    ... I want it to show with two decimals and ... But when I go to the actual layout the field jumps ... now it starts with cutting the right digits again. ...
    (comp.databases.filemaker)
  • Re: GetKeyState() problem
    ... especially for the toggle keys. ... > No, no layout manager stuff. ... >> input system's understanding of these modifier flags. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: [PATCH] x86: small unifications of address printing
    ... for the %p conversion specifier. ... Problem is that %p will not pad to 8/16 digits. ... flags |= ZEROPAD; ...
    (Linux-Kernel)