locked
data type problem in c# RRS feed

  • Question

  • in C++:

    unsinged int mdata=0x3dfcd35b;

    float fdata=*(float*)(&mdata);

    printf("%f ",fdata);

     

    0.12345    It's an IEEE single-precision floating-point data format

     

    now,in C# ,we can not use pointer,

    how can fdata be 0.12345?

    Sunday, August 12, 2007 9:34 AM

Answers

  • public unsafe static class Convertor

    {

        public static float ConvertIEEE754(string value)

        {

            uint mdata = Convert.ToUInt32(value, 16);

            float fdata=*(float*)(&mdata);

            return fdata;

        }

    }

     

    float f = Convertor.ConvertIEEE754("0x3dfcd35b");


    f will contain 0.12345

    Sunday, August 12, 2007 10:03 AM

All replies

  • public unsafe static class Convertor

    {

        public static float ConvertIEEE754(string value)

        {

            uint mdata = Convert.ToUInt32(value, 16);

            float fdata=*(float*)(&mdata);

            return fdata;

        }

    }

     

    float f = Convertor.ConvertIEEE754("0x3dfcd35b");


    f will contain 0.12345

    Sunday, August 12, 2007 10:03 AM
  •  

    Thank you!
    Sunday, August 12, 2007 10:23 AM