1. Convert from hexadecimal to decimal
/// <Summary> // convert the hexadecimal format to decimal format /// </Summary> /// <Param name = "hex"> </param> /// <returns> </returns> Public static string hex2ten (string HEX) {int ten = 0; For (INT I = 0, j = hex. length-1; I
this.txtStartShi.Text = Hex2Ten(this.txtStartSN.Text.Trim().Substring(4, 8));this.txtEndShi.Text = Hex2Ten(this.txtEndSN.Text.Trim().Substring(4, 8));
2. Convert from decimal to hexadecimal
/// <Summary> /// convert from decimal to hexadecimal // </Summary> /// <Param name = "Ten"> </param> // /<returns> </returns> Public static string ten2hex (string ten) {ulong tenvalue = convert. touint64 (TEN); ulong divvalue, resvalue; string hex = ""; do {// divvalue = (ulong) math. floor (tenvalue/16); divvalue = (ulong) math. floor (decimal) (tenvalue/16); resvalue = tenvalue % 16; hex = tenvalue2char (resvalue) + hex; tenv Alue = divvalue;} while (tenvalue> = 16); If (tenvalue! = 0) hex = tenvalue2char (tenvalue) + hex; return hex;} public static string tenvalue2char (ulong ten) {Switch (TEN) {Case 0: Case 1: Case 2: case 3: Case 4: Case 5: Case 6: Case 7: Case 8: Case 9: return ten. tostring (); case 10: Return "A"; Case 11: Return "B"; Case 12: Return "C"; Case 13: Return "D"; Case 14: return "e"; Case 15: Return "F"; default: Return "";}}
int StartSN = Convert.ToInt32(this.txtStartShi.Text.Trim());int EndSN = Convert.ToInt32(this.txtEndShi.Text.Trim()); for (int i = 0; i < EndSN - StartSN + 1; i++) { listBox1.Items.Add("0014" + Ten2Hex((Convert.ToDouble(this.txtStartShi.Text) + i).ToString())); }