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

  • SEARCH
  • Home
  • 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 6979045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:50:07+00:00 2026-05-27T17:50:07+00:00

I have a IEEE754 Double precision 64-bit binary string representation of a double number.

  • 0

I have a IEEE754 Double precision 64-bit binary string representation of a double number.
example : double value = 0.999;
Its binary representation is “0011111111101111111101111100111011011001000101101000011100101011”

I want to convert this string back to a double number in c++.
I dont want to use any external libraries or .dll’s as my program would operate in any platform.

  • 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. Editorial Team
    Editorial Team
    2026-05-27T17:50:08+00:00Added an answer on May 27, 2026 at 5:50 pm

    C string solution:

    #include <cstring>   // needed for all three solutions because of memcpy
    
    double bitstring_to_double(const char* p)
    {
        unsigned long long x = 0;
        for (; *p; ++p)
        {
            x = (x << 1) + (*p - '0');
        }
        double d;
        memcpy(&d, &x, 8);
        return d;
    }
    

    std::string solution:

    #include <string>
    
    double bitstring_to_double(const std::string& s)
    {
        unsigned long long x = 0;
        for (std::string::const_iterator it = s.begin(); it != s.end(); ++it)
        {
            x = (x << 1) + (*it - '0');
        }
        double d;
        memcpy(&d, &x, 8);
        return d;
    }
    

    generic solution:

    template<typename InputIterator>
    double bitstring_to_double(InputIterator begin, InputIterator end)
    {
        unsigned long long x = 0;
        for (; begin != end; ++begin)
        {
            x = (x << 1) + (*begin - '0');
        }
        double d;
        memcpy(&d, &x, 8);
        return d;
    }
    

    example calls:

    #include <iostream>
    
    int main()
    {
        const char * p = "0011111111101111111101111100111011011001000101101000011100101011";
        std::cout << bitstring_to_double(p) << '\n';
    
        std::string s(p);
        std::cout << bitstring_to_double(s) << '\n';
    
        std::cout << bitstring_to_double(s.begin(), s.end()) << '\n';
        std::cout << bitstring_to_double(p + 0, p + 64) << '\n';
    }
    

    Note: I assume unsigned long long has 64 bits. A cleaner solution would be to include <cstdint> and use uint64_t instead, assuming your compiler is up to date and provides that C++11 header.

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

Sidebar

Related Questions

Good Day, I have a number of binary strings that were created by a
Suppose I have a hex number 4072508200000000 and I want the floating point number
I have a binary file which is simple a list of signed 32 bit
In MATLAB (r2009b) I have a uint32 variable containing the value 2147484101. This number
Have you determined a maximum number of characters allowed in FCKEditor ? I seem
I have a 32-bit integer. The bit stream is actually a bit stream for
I have a unsigned long integer value which represents a float using IEEE-754 format.
I'm having problems parsing a hex formatted DEC 32bit single precision floating point value
Have finally got a responsive site working (of a fashion). What I want to
Is it a good idea to use IEEE754 floating point NaN (not-a-number) for values

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.