Convert integer to hexadecimal and back again

前端 未结 10 2171
轮回少年
轮回少年 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:38

    Use:

    int myInt = 2934;
    string myHex = myInt.ToString("X");  // Gives you hexadecimal
    int myNewInt = Convert.ToInt32(myHex, 16);  // Back to int again.
    

    See How to: Convert Between Hexadecimal Strings and Numeric Types (C# Programming Guide) for more information and examples.

提交回复
热议问题