Newbie Question: decimal variable type

  • Thread starter Thread starter Blue Streak
  • Start date Start date
B

Blue Streak

Hi, folks!

I read somewhere that the decimal variable type uses 128-bits in
memory for each variable. However, I read from other sources that the
decimal type only uses 96-bits to store the number.

Does anyone know the real number and why there might be a discrepancy?

TIA...
 
Blue Streak said:
I read somewhere that the decimal variable type
uses 128-bits in memory for each variable.
However, I read from other sources that the
decimal type only uses 96-bits to store the number.

So perform the experiment yourself:

Console.WriteLine(sizeof(decimal) * 8);

Eq.
 
This is from the MSDN Library (so you can believe it, rather than something
you "read somewhere"):

"The binary representation of a Decimal value consists of a 1-bit sign, a
96-bit integer number, and a scaling factor used to divide the 96-bit
integer and specify what portion of it is a decimal fraction. The scaling
factor is implicitly the number 10, raised to an exponent ranging from 0 to
28. "

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
Blue Streak said:
I read somewhere that the decimal variable type uses 128-bits in
memory for each variable. However, I read from other sources that the
decimal type only uses 96-bits to store the number.

Does anyone know the real number and why there might be a discrepancy?

Decimal uses 96 bits to store the mantissa, 5 bits to store the
exponent, and 1 bit to store the sign. However, it's stored as a 128
bit value. So yes, 26 bits are wasted - but it would be hard to put
them to good use.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top