C # decimal and 16 binary conversions

Source: Internet
Author: User

Go to: http://www.cnblogs.com/fwind/archive/2012/04/13/2445380.html

In C #, the decimal and 16 binary conversions are simple, as follows:

Decimal to hexadecimal:

int  -  = a.tostring ("x8");

Hexadecimal to decimal:

int b= int32.parse ("266", System.Globalization.NumberStyles.HexNumber);

You can also use the following methods:

/// <summary>        ///hexadecimal conversion to decimal/// </summary>        /// <param name= "Strcolorvalue" ></param>        /// <returns></returns>         Public Static intGethexadecimalvalue (String strcolorvalue) {Char[] Nums =Strcolorvalue.tochararray (); intTotal =0; Try            {                 for(inti =0; I < Nums. Length; i++) {String strnum=Nums[i]. ToString ().                    ToUpper (); Switch(strnum) { Case "A": Strnum="Ten";  Break;  Case "B": Strnum=" One";  Break;  Case "C": Strnum=" A";  Break;  Case "D": Strnum=" -";  Break;  Case "E": Strnum=" -";  Break;  Case "F": Strnum=" the";  Break; default:                             Break; }                    DoublePower = Math.pow ( -, Convert.todouble (nums. Length-i-1)); Total+ = Convert.ToInt32 (strnum) *Convert.ToInt32 (Power); }            }            Catch(System.Exception ex) {String Strerorr=Ex.                ToString (); return 0; }            returnTotal ; }

C # decimal and 16 binary conversions

Related Article

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.