How to convert numbers between hexadecimal and decimal

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

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

17条回答
  •  灰色年华
    2020-11-22 06:07

    From Geekpedia:

    // Store integer 182
    int decValue = 182;
    
    // Convert integer 182 as a hex in a string variable
    string hexValue = decValue.ToString("X");
    
    // Convert the hex string back to the number
    int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
    

提交回复
热议问题