How to convert System.Decimal bits to string in C#?

前端 未结 4 1820
天涯浪人
天涯浪人 2021-01-18 20:36

I\'d like to be able to get the bits from a System.Decimal value and then convert that to the string representation of the value, much like Decimal.ToStri

4条回答
  •  情书的邮戳
    2021-01-18 20:55

    It's does not algoritm, but i suppose it should help.

    Decimal bits structure:

    The binary representation of a Decimal number consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the integer number and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28.

    The return value is a four-element array of 32-bit signed integers.

    The first, second, and third elements of the returned array contain the low, middle, and high 32 bits of the 96-bit integer number.

    The fourth element of the returned array contains the scale factor and sign. It consists of the following parts:

    Bits 0 to 15, the lower word, are unused and must be zero.

    Bits 16 to 23 must contain an exponent between 0 and 28, which indicates the power of 10 to divide the integer number.

    Bits 24 to 30 are unused and must be zero.

    Bit 31 contains the sign; 0 meaning positive, and 1 meaning negative.

提交回复
热议问题