Convert a number into the hex value in .NET

前端 未结 2 372
离开以前
离开以前 2020-12-16 14:59

I need to convert an integer number to the hex value. It will look like this:

0x0201cb77192c851c

When I do

string hex = int         


        
相关标签:
2条回答
  • 2020-12-16 15:42

    One way would be to append the number of digits you need, after "x". This will pad the output with leading zeros as necessary.

    "0x" + myLong.ToString("x16");
    

    or

    string.Format("0x{0:x16}", myLong);
    

    From The Hexadecimal ("X") Format Specifier :

    The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier.

    0 讨论(0)
  • 2020-12-16 15:54
    string hex = "0x" + int.ToString("x16")
    
    0 讨论(0)
提交回复
热议问题