Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 102199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:55:03+00:00 2026-05-11T00:55:03+00:00

Is there any straightforward way to get the mantissa and exponent from a double

  • 0

Is there any straightforward way to get the mantissa and exponent from a double in c# (or .NET in general)?

I found this example using Google, but I’m not sure how robust it would be. Could the binary representation for a double change in some future version of the framework, etc?

The other alternative I found was to use System.Decimal instead of double and use the Decimal.GetBits() method to extract them.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:55:04+00:00Added an answer on May 11, 2026 at 12:55 am

    The binary format shouldn’t change – it would certainly be a breaking change to existing specifications. It’s defined to be in IEEE754 / IEC 60559:1989 format, as Jimmy said. (C# 3.0 language spec section 1.3; ECMA 335 section 8.2.2). The code in DoubleConverter should be fine and robust.

    For the sake of future reference, the relevant bit of the code in the example is:

    public static string ToExactString (double d) {     …      // Translate the double into sign, exponent and mantissa.     long bits = BitConverter.DoubleToInt64Bits(d);     // Note that the shift is sign-extended, hence the test against -1 not 1     bool negative = (bits & (1L << 63)) != 0;     int exponent = (int) ((bits >> 52) & 0x7ffL);     long mantissa = bits & 0xfffffffffffffL;      // Subnormal numbers; exponent is effectively one higher,     // but there's no extra normalisation bit in the mantissa     if (exponent==0)     {         exponent++;     }     // Normal numbers; leave exponent as it is but add extra     // bit to the front of the mantissa     else     {         mantissa = mantissa | (1L << 52);     }      // Bias the exponent. It's actually biased by 1023, but we're     // treating the mantissa as m.0 rather than 0.m, so we need     // to subtract another 52 from it.     exponent -= 1075;      if (mantissa == 0)      {         return negative ? '-0' : '0';     }      /* Normalize */     while((mantissa & 1) == 0)      {    /*  i.e., Mantissa is even */         mantissa >>= 1;         exponent++;     }      … } 

    The comments made sense to me at the time, but I’m sure I’d have to think for a while about them now. After the very first part you’ve got the ‘raw’ exponent and mantissa – the rest of the code just helps to treat them in a simpler fashion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Related Questions

Loading...

Sidebar

Ask A Question

Stats

  • Questions 54k
  • Answers 55k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer A wild guess: there is a directory named 'news', and… May 11, 2026 at 7:35 am
  • added an answer Turns out that this behaviour is possible with Moq as… May 11, 2026 at 7:35 am
  • added an answer By using SSL. EDIT A nice resource of information about… May 11, 2026 at 7:35 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.