标签:style blog color os io 数据 for ar
static string DecimalismConversion(string x, int y) { Stack stack = new Stack(); int length = Int64.MaxValue.ToString().Length - 2; while ( x!="") { string quotient = string.Empty; string remainder = string.Empty; int count = 0; Int64 i64 = 0; while (count * length < x.Length) { string str = x.Substring(count * length, Math.Min(length, x.Length - count * length)); i64 = Convert.ToInt64(remainder + str); remainder = (i64 % y).ToString(); quotient += (i64 / y).ToString().PadLeft(str.Length, ‘0‘); count++; } Int64.TryParse(remainder, out i64); if (i64 % y < 10) stack.Push((char)(i64 % y + 48)); else stack.Push((char)(i64 % y + 55)); x = quotient.TrimStart(new char[] { ‘ ‘, ‘0‘ }); } return new string(stack.ToArray()); }
以下这段是它的原身,现在想想就可笑,以前写程序设计(c语言),那么难看。
int main(int x,int y) { int i=0; char a[17]; printf("Input:"); L: scanf("%d %d",&x,&y); if(x<=0||y<=2||y>=33) { printf("Input error,input again:"); goto L; } while(x!=0) { if(x%y<10) a=(char)(x%y+48); else a=(char)(x%y+55); x=x/y; } for(i=i-1;i>=0;i--) printf("%c",a); putchar(‘\n‘); }
C# 进制转换 (没有数值的长度限制),布布扣,bubuko.com
标签:style blog color os io 数据 for ar
原文地址:http://www.cnblogs.com/preacher/p/3906734.html