Convert integer to hexadecimal and back again

前端 未结 10 2159
轮回少年
轮回少年 2020-11-22 02:33

How can I convert the following?

2934 (integer) to B76 (hex)

Let me explain what I am trying to do. I have User IDs in my database that are stored as inte

10条回答
  •  爱一瞬间的悲伤
    2020-11-22 02:39

    Print integer in hex-value with zero-padding (if needed) :

    int intValue = 1234;
    
    Console.WriteLine("{0,0:D4} {0,0:X3}", intValue); 
    

    https://docs.microsoft.com/en-us/dotnet/standard/base-types/how-to-pad-a-number-with-leading-zeros

提交回复
热议问题