从int转换为十六进制

Cat*_*ine 4 c# string hex

我想将一些整数转换为十六进制,但我得到的是这样的东西:"?| ??? plL4?h ?? N {"来自12345.为什么?

int t = 12345;

System.Security.Cryptography.MD5CryptoServiceProvider ano = new
System.Security.Cryptography.MD5CryptoServiceProvider();

byte[] d_ano = System.Text.Encoding.ASCII.GetBytes(t.ToString());
byte[] d_d_ano = ano.ComputeHash(d_ano);

string st_data1 = System.Text.Encoding.ASCII.GetString(d_d_ano);
string st_data = st_data1.ToString();
Run Code Online (Sandbox Code Playgroud)

我在窗口中使用它,而不是在控制台中.

Ily*_*gan 9

要将数字转换为十六进制,只需使用:

integerValue.ToString("X")
Run Code Online (Sandbox Code Playgroud)


Bab*_*fas 5

如果您想要做的只是转换,为什么要使用加密?

对于实际转换,请使用此代码段

int myNumber = 42;
String myHexNumber = myNumber.ToString("X");
Run Code Online (Sandbox Code Playgroud)