Beispiel #1
0
    /// <summary>
    /// 十进制数字转换为任意进制格式
    /// </summary>
    /// <returns></returns>
    public static string Decimal2Radix(decimal d, byte b = 2, byte p = 64)
    {
        int     i = Mathr.Decimal2Integer(d);
        decimal f = Mathr.Decimal2Fraction(d);

        return(Integer2Radix(i, b) + "." + Fraction2Radix(f, b));
    }
Beispiel #2
0
    /// <summary>
    /// 十进制分数部分转换
    /// </summary>
    /// <returns></returns>
    private static string Fraction2Radix(decimal f, byte b, byte p = 64)
    {
        string output = "";
        int    count  = 0;

        do
        {
            decimal result = f * b;
            int     i      = Mathr.Decimal2Integer(result);
            f       = Mathr.Decimal2Fraction(result);
            output += i;
            count++;
        }while (f != 0 && count < p);
        return(output);
    }