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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:31:07+00:00 2026-05-13T16:31:07+00:00

I am trying to convert scientific double to decimal double in java. I am

  • 0

I am trying to convert scientific double to decimal double in java. I am sending a value from server (coded on C++) which is running on X86 (little endian) machine and I was using htonl, ntohl methods for convertion before sending data to client (coded on java). But now, I have to sent this value with no conversion like LE to BE. The coversion is being done on client (java) side. Other type can be converted correctly but for double, this is not present. When client receive a double type, this value can not be read correctly. Here is my java code for double conversion.

protected int readInt(InputStream stream) throws IOException {
    int i0 = read(stream);
    int i1 = read(stream);
    int i2 = read(stream);
    int i3 = read(stream);
     int i=(i0 << 24) + (i1 << 16) + (i2 << 8) + (i3 << 0);
    return i;
}
protected double readDouble(InputStream stream) throws IOException {
    int i0 = readInt(stream);
    int i1 = readInt(stream);
    return Double.longBitsToDouble(((long)i0 << 32) + (i1 & 0xffffffffL));      
}

After all of these steps, I got 9.534475227E-315 if I sent 0.3 from server.
Thanks and regards.

  • 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-13T16:31:08+00:00Added an answer on May 13, 2026 at 4:31 pm

    I solved the my question and thank to you all for your helps. Much appreciated. So here is the solution.

      protected double readDouble(InputStream stream) throws IOException {
    
        return Double.longBitsToDouble(((long) read(stream) & 0xff) 
                                     | ((long) (read(stream) & 0xff) << 8)
                                     | ((long) (read(stream) & 0xff) << 16)
                                     | ((long) (read(stream) & 0xff) << 24)
                                     | ((long) (read(stream) & 0xff) << 32)
                                     | ((long) (read(stream) & 0xff) << 40)
                                     | ((long) (read(stream) & 0xff) << 48)                     
                                     | ((long) (read(stream) & 0xff) << 56));  }
    

    When I send a data from server in little endian format, I can convert incoming little endian formatted value to big endian formatted value with this code in java.

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

Sidebar

Related Questions

Whilst trying to convert the number from the value of a numericupdown to an
Trying to convert output from a rest_client GET to the characters that are represented
I'trying to convert a float to an int value in php: var_dump((int)(39.3 * 100.0));
I am trying to convert a Guice inject project to a Java EE project,
I'm trying to convert a set of strings from a txt file into int's
How to extract and save array from string parameter? I'm trying convert string beafore_create
I'm trying to convert a user ID from a User class and store it
I'm trying convert xml from one format to other using the XslCompiledTransform in c#.
I am trying convert the following Collatz Conjecture algorithm from: public class CollatzConjexture {
I am trying convert the following Collatz Conjecture algorithm from: public class CollatzConjexture {

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.