How to convert numbers between hexadecimal and decimal

前端 未结 17 1356
情歌与酒
情歌与酒 2020-11-22 05:30

How do you convert between hexadecimal numbers and decimal numbers in C#?

17条回答
  •  庸人自扰
    2020-11-22 06:07

    To convert from decimal to hex do...

    string hexValue = decValue.ToString("X");
    

    To convert from hex to decimal do either...

    int decValue = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
    

    or

    int decValue = Convert.ToInt32(hexValue, 16);
    

提交回复
热议问题