Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

Newbie Question: decimal variable type

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Blue Streak - 12 Oct 2007 17:37 GMT
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...
Paul E Collins - 12 Oct 2007 17:50 GMT
> 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.
Kevin Spencer - 12 Oct 2007 18:01 GMT
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. "

Signature

HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

> Hi, folks!
>
[quoted text clipped - 5 lines]
>
> TIA...
Jon Skeet [C# MVP] - 12 Oct 2007 18:57 GMT
> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.