Convert from IBM floating point to IEEE floating point standard and Vice Versa- In C#?

前端 未结 4 1469
慢半拍i
慢半拍i 2020-12-06 13:10

Was looking for a way to IEEE floating point numbers to IBM floating point format for a old system we are using.

Is there a general formula we can use in C# to this

4条回答
  •  粉色の甜心
    2020-12-06 13:52

    I recently had to convert one float to another. It looks like XDR format uses an odd format for its floats. So when converting from XDR to standard floats, this code did it.

    #include 
    
    // Read in XDR float array, copy to standard float array
    // out array needs to be allocated before the function call
    
    bool convertFromXdrFloatArray(float *in, float *out, long size)
    {
        XDR xdrs;
        xdrmem_create(&xdrs,(char *)in, size*sizeof(float), XDR_DECODE);
    
        for(int i = 0; i < size; i++)
        {
            if(!xdr_float(&xdrs, out++)) {
                fprintf(stderr,"%s:%d:ERROR:xdr_float\n",__FILE__,__LINE__);
                exit(1);
            }
        }
        xdr_destroy(&xdrs);
    
        return true;
    }
    

提交回复
热议问题