CIL and JVM Little endian to big endian in c# and java

Posted by Haythem on Stack Overflow See other posts from Stack Overflow or by Haythem
Published on 2010-04-27T08:21:37Z Indexed on 2010/04/27 8:23 UTC
Read the original article Hit count: 364

Hello,

I am using on the client C# where I am converting double values to byte array.

I am using java on the server and I am using writeDouble and readDouble to convert double values to byte arrays.

The problem is the double values from java at the end are not the double values at the begin giving to c#

writeDouble in Java Converts the double argument to a long using the doubleToLongBits method , and then writes that long value to the underlying output stream as an 8-byte quantity, high byte first.

DoubleToLongBits Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout.

The Program on the server is waiting of 64-102-112-0-0-0-0-0 from C# to convert it to 1700.0 but he si becoming 0000014415464 from c# after c# converted 1700.0

this is my code in c#:

 class User
  {
    double workingStatus;
public void persist()
   {
     byte[] dataByte;
   using (MemoryStream ms = new MemoryStream())
     {
       using (BinaryWriter bw = new BinaryWriter(ms))
       {

         bw.Write(workingStatus);
         bw.Flush();
         bw.Close();
       }

    dataByte = ms.ToArray();

       for (int j = 0; j < dataByte.Length; j++)
       {

         Console.Write(dataByte[j]);
       }
}
public double WorkingStatus
      {
     get { return workingStatus; }
     set { workingStatus = value; }
      }

}
class Test
{
  static void Main()
  {
    User user = new User();
     user.WorkingStatus = 1700.0;
     user.persist();
  }

thank you for the help.

© Stack Overflow or respective owner

Related posts about c#

Related posts about endianness