示例#1
0
        // return string representation in given radix
        public string ToString(int radix)
        {
            if (sign < 0)
            {
                return("-" + Negate.ToString(radix));
            }
            var k = 0;

            switch (radix)
            {
            case 16:
                k = 4;
                break;

            case 8:
                k = 3;
                break;

            case 2:
                k = 1;
                break;

            case 32:
                k = 5;
                break;

            case 4:
                k = 2;
                break;

            default:
                return(ToRadix(radix));
            }
            var km     = (1 << k) - 1;
            var d      = 0;
            var m      = false;
            var result = string.Empty;
            var i      = t;
            var p      = DB - (i * DB) % k;

            if (i-- > 0)
            {
                if (p < DB && (d = this[i] >> p) > 0)
                {
                    m      = true;
                    result = Int2Char(d).ToString();
                }
                while (i >= 0)
                {
                    if (p < k)
                    {
                        d  = (this[i] & ((1 << p) - 1)) << (k - p);
                        d |= this[--i] >> (p += DB - k);
                    }
                    else
                    {
                        d = (this[i] >> (p -= k)) & km;
                        if (p <= 0)
                        {
                            p += DB;
                            i--;
                        }
                    }
                    m |= d > 0;
                    if (m)
                    {
                        result += Int2Char(d);
                    }
                }
            }
            return(m ? result : "0");
        }
        public void NegateTest2()
        {
            Negate c = new Negate(CardSuit.Club, (byte)1);

            Assert.AreEqual("Negate", c.ToString());
        }