In C #, decimal and hexadecimal conversion is very simple. The method is as follows:
Convert decimal to hexadecimal:
1 int a = 100;2 String strA = a.ToString("x8");
Convert hexadecimal to decimal:
1 int b= Int32.Parse("266", System.Globalization.NumberStyles.HexNumber);
You can also use the following methods:
1 /// <summary> 2 // convert the hexadecimal format to 3 /// </summary> 4 /// <param name = "strColorValue"> </param> 5 // <returns> </returns> 6 public static int GetHexadecimalValue (String strColorValue) 7 {8 char [] nums = strColorValue. toCharArray (); 9 int total = 0; 10 try11 {12 for (int I = 0; I <nums. length; I ++) 13 {14 String strNum = nums [I]. toString (). toUpper (); 15 switch (strNum) 16 {17 case "A": 18 strNum = "10"; 19 break; 20 case "B": 21 strNum = "11 "; 22 break; 23 case "C": 24 strNum = "12"; 25 break; 26 case "D": 27 strNum = "13"; 28 break; 29 case "E": 30 strNum = "14"; 31 break; 32 case "F": 33 strNum = "15"; 34 break; 35 default: 36 break; 37} 38 double power = Math. pow (16, Convert. toDouble (nums. length-I-1); 39 total + = Convert. toInt32 (strNum) * Convert. toInt32 (power); 40} 41 42} 43 catch (System. exception ex) 44 {45 String strErorr = ex. toString (); 46 return 0; 47} 48 49 50 return total; 51}