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 9039719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:47:58+00:00 2026-06-16T09:47:58+00:00

I have problem converting String^ containing 8 bytes as characters (as ascii) to double.

  • 0

I have problem converting String^ containing 8 bytes as characters (as ascii) to double.
I want to take those 8 characters and convert them binary to double.

What would you recommend to do this conversion in C++/cli?

I was trying to use Marshal::Copy, Double::TryParse, etc.

Maybe I use wrong specifications of parameters, but I really lost my last hopes.
There must be something easy to do this conversion.

Thanks.

  • 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-06-16T09:47:59+00:00Added an answer on June 16, 2026 at 9:47 am

    Well, the bad news is that the System.String class uses only Unicode encoding internally.

    So if you give it bytes it will map them to its internal encoding hiding the original value.

    The good news is that you can play with the System.Text.Encoding class to retrieve 8bits values corresponding to the unicode characters.

    Here is a sample :

    #include <iostream>
    
    using namespace System;
    using namespace System::Text;
    
    int main()
    {
        int n = 123456;
        double d = 123.456;
    
        std::cout << n << std::endl;
        std::cout << d << std::endl;
    
        char* n_as_bytes = (char*)&n;
        char* d_as_bytes = (char*)&d;
    
        String^ n_as_string = gcnew String(n_as_bytes, 0, sizeof(n));
        String^ d_as_string = gcnew String(d_as_bytes, 0, sizeof(d));
    
        Encoding^ ascii = Encoding::GetEncoding("iso-8859-1");
    
        array<Byte>^ n_as_array = ascii->GetBytes(n_as_string);
        array<Byte>^ d_as_array = ascii->GetBytes(d_as_string);
    
        cli::pin_ptr<unsigned char> pin_ptr_n = &n_as_array[0];
        cli::pin_ptr<unsigned char> pin_ptr_d = &d_as_array[0];
    
        unsigned char* ptr_n = pin_ptr_n;
        unsigned char* ptr_d = pin_ptr_d;
    
        int n_out = *(int*)ptr_n;
        double d_out = *(double*)ptr_d;
    
        std::cout << n_out << std::endl;
        std::cout << d_out << std::endl;
    
        return 0;
    }
    

    This should give you :

    123456
    123.456
    123456
    123.456
    

    Not sure it is completely safe, but trying it in your context should be a good start to ensure it is viable. 🙂

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

Sidebar

Related Questions

I have a problem converting a string binary to a decimal I was using
I have a weird problem in converting a string to double in .NET 3.5.
I have no problem converting normal double values, but I can't convert numeric_limits<double>::max( )
I have one specific problem while converting double values to string using sprintf() in
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I am using LaTeX and I have a problem concerning string manipulation. I want
I have a problem with converting string to float. print gettype($value[$id]); //returns string var_dump($value[$id]);//returns
Hi stackoverflow team i have a problem in converting base64 string to bitmap in
I have problem converting from string to date. The first one i Ok: Date
I have a problem on converting JSON string to object in Android. Here are

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.