예제 #1
0
파일: Any2Dec.cs 프로젝트: mobangjack/cns
        public static ulong convert(string numStr, byte orgSys)
        {
            ulong result = 0;

            for (int i = 0; i < numStr.Length; i++)
            {
                result = result * orgSys + (ulong)(Digits.Dec(numStr.ElementAt(i)));
            }
            return(result);
        }
예제 #2
0
        public static string convert(ulong numDec, byte dstSys)
        {
            Stack <char> digitCharStack = new Stack <char>();
            ulong        quotient       = numDec;
            byte         remainder      = 0;

            while (quotient != 0)
            {
                remainder = (byte)(quotient % dstSys);
                quotient  = quotient / dstSys;
                digitCharStack.Push(Digits.Any(remainder));
            }
            StringBuilder stringBuilder = new StringBuilder(digitCharStack.Count);

            while (digitCharStack.Count > 0)
            {
                stringBuilder.Append(digitCharStack.Pop());
            }
            return(stringBuilder.ToString());
        }
예제 #3
0
 public static string convert(string numStr, char orgSys, char dstSys)
 {
     return(convert(numStr, (byte)(Digits.Dec(orgSys) + 1), (byte)(Digits.Dec(dstSys) + 1)));
 }