Numerical hexadecimal conversion C #

Source: Internet
Author: User

 

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:

  • More common 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  

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.