How to convert numbers between hexadecimal and decimal

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

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

17条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 06:05

    Try using BigNumber in C# - Represents an arbitrarily large signed integer.

    Program

    using System.Numerics;
    ...
    var bigNumber = BigInteger.Parse("837593454735734579347547357233757342857087879423437472347757234945743");
    Console.WriteLine(bigNumber.ToString("X"));
    

    Output

    4F30DC39A5B10A824134D5B18EEA3707AC854EE565414ED2E498DCFDE1A15DA5FEB6074AE248458435BD417F06F674EB29A2CFECF
    

    Possible Exceptions,

    ArgumentNullException - value is null.

    FormatException - value is not in the correct format.

    Conclusion

    You can convert string and store a value in BigNumber without constraints about the size of the number unless the string is empty and non-analphabets

提交回复
热议问题