using System; using System.Collections.Generic; using System.Text; namespace Call.tool { class DtoX { /// <summary> /// 十进制转为十六进制 /// </summary> /// <param name="d"></param> /// <returns></returns> public static string DToX(int d) { string x = ""; if (d < 16) { x = chang(d); } else { int c; int s = 0; int n = d; int temp = d; while (n >= 16) { s++; n = n / 16; } string[] m = new string[s]; int i = 0; do { c = d / 16; m[i++] = chang(d % 16);//判断是否大于10,如果大于10,则转换为A~F的格式 d = c; } while (c >= 16); x = chang(d); for (int j = m.Length - 1; j >= 0; j--) { x += m[j]; } } return x; } static string chang(int d) { string x = ""; switch (d) { case 10: x = "A"; break; case 11: x = "B"; break; case 12: x = "C"; break; case 13: x = "D"; break; case 14: x = "E"; break; case 15: x = "F"; break; default: x = d.ToString(); break; } return x; } } }