存个档;
//十进制转成任意进制 private static string GetCusSN(int num, int strLen, string serialChars) { int slen = serialChars.Length; if (num > Math.Pow(slen, strLen) - 1) return "-1"; string sn = ""; if (num <= slen - 1) sn = serialChars.Substring(num, 1); else { while (num > slen - 1) { int remainder = num % slen; num /= slen; sn = serialChars.Substring(remainder, 1) + sn; if (num <= slen - 1) sn = serialChars.Substring(num, 1) + sn; } } return sn.PadLeft(strLen, serialChars.Left(1).ToCharArray()[0]); } //十进制左边补0 private static string GetDecSN(int num, int decLen) { if (num > Math.Pow(10, decLen) - 1) return "-1"; else return $"{num}".PadLeft(decLen, '0'); }
标签:slen,进制,int,num,serialChars,return,任意,十进制,string From: https://www.cnblogs.com/leavind/p/16937706.html