|
Up
About
private string convert(long num, int newBase) { int d; char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; StringBuilder output = new StringBuilder(); // calculate the new output digits, working right to left while (num > 0) { d = (int)(num % newBase); // calculate the current output digit output.Append(digits[d]); // append the digit's character to the result string num /= newBase; // divide the input number by the base } // reverse the output buffer and return it as a string return reverse(output.ToString()); } private string reverse(string str) { char[] c = str.ToCharArray(); Array.Reverse(c); return new string(c); }
private String convert(long num, int newBase) { return Long.toString(num, newBase); }