In daily applications, commonly used numeric hexadecimalDecimal, octal, hexadecimal, and binary.
In. net, it is very simple and convenient to implement digital conversion. There are two general implementation methods:
System. Convert. toint ?? (?, Int frombase) // frombase indicates the base number, which can be 2, 8, 16 system. Convert. tostring (?, Int tobase) // tobase is the hexadecimal format to be converted. It can be 2, 8, or 16.
- It is applicable to interchange between 10-and 16-digit systems.
Int. parse (string S, system. Globalization. numberstyles. hexnumber) // and Int. tostring ("X ") //
Example of the first method:
string hexNumber = "0F";int digitNumber = System.Convert.ToInt32 ( hexNumber, 16 );hexNumber = System.Convert.ToString ( digitNumber, 16 );
Example of the second method:
int digitNumber = 100;string hexNumber = digitNumber.ToString ( "X" );digitNumber = int.Parse ( hexNumber, System.Globalization.NumberStyles.HexNumber );
Tostring ("? ") Common formatting methods:
| Symbol |
Description |
Example |
Output result |
Remarks |
| C |
Currency |
(3.8). tostring ("C ") |
¥3.80 |
Display Method of currency result, and System. Globalization. cultureinfo. currentculture Settings |
| D |
Decimal digital |
(38). tostring ("D6 ") |
000038 |
"In" D6"6"Indicates the length of the returned string. |
| E |
Scientific type |
(3800). tostring ("e ") |
3.800000e + 004 |
|
| F |
Float |
(38). tostring ("F3 ") |
38.000 |
"In" F3"3"Is the number of decimal places |
| G |
General |
(38). tostring ("G ") |
38 |
|
| N |
|
(12345). tostring ("N ") |
12,345.00 |
|
| X |
Hexadecimal |
(38). tostring ("X ") |
26 |
|