double to hex string & hex string to double

后端 未结 9 1420
南方客
南方客 2021-01-02 20:51

What I\'m trying to do is to convert a double to hex string and then back to double.

The following code does conversion double-to-hex string.

char *          


        
9条回答
  •  独厮守ぢ
    2021-01-02 21:42

    For MFC, convert double to CString :)

    CString MFCClass::DoubleToCString(double d, int beforKomma)
    {
        char a[17]="0123456789ABCDEF";
        CString str = _T("");
        double dInt=0,dPunkt=0;
        bool is_otr=0;
        if (d<0) {is_otr=1; d=-d;}
        dPunkt = modf(d, &dInt);
        //целая часть
        long ld = (long)dInt;
        long mask = 0xf;
        int it;
        while(ld>0)
        {
            it = ld&mask;
            ld = ld>>4;
            str.Insert(0,a[it]);
        };
        // дробная часть
        //если целая часть 0:
        if (str.GetLength()==0) str += _T("0");
        str += _T(".");
        for (int i=0; i

    -345.86783907228863 -> "-159.DE2" (beforKomma=3)

提交回复
热议问题