Re: Decimal Data Type bit layout
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Sat, 10 Sep 2005 18:00:19 +0200
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
>>
.
- Follow-Ups:
- Re: Decimal Data Type bit layout
- From: Peter Sestoft
- Re: Decimal Data Type bit layout
- References:
- Decimal Data Type bit layout
- From: mdavidjohnson
- Re: Decimal Data Type bit layout
- From: Jon Skeet [C# MVP]
- Re: Decimal Data Type bit layout
- From: mdavidjohnson
- Decimal Data Type bit layout
- Prev by Date: Re: Decimal Data Type bit layout
- Next by Date: Using TypeBuilder and System.Reflection.Emit to generate an assembly
- Previous by thread: Re: Decimal Data Type bit layout
- Next by thread: Re: Decimal Data Type bit layout
- Index(es):
Relevant Pages
|