converting from int to hex
I want to convert some ints to hex,but i'm getting something like this : "?|???plL4?h??N{" from 12345. Why?
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();
I'm using it in window 开发者_开发问答form,not in console.
To convert a number to hex, just use:
integerValue.ToString("X")
Why are you using encryption if all you want to do is conversion?
For the actual conversion, use this snippet
int myNumber = 42;
String myHexNumber = myNumber.ToString("X");
value.ToString("X") is all you need
int t = 12345;
Console.WriteLine("{0:X4}", t);
no?
use Convert.ToString(intValue, 16);
Edit: this way can be used in all bases like Convert.ToString(intValue, 2)
Looks like you want to convert int to a hex string.
int t = 12345;
string hex = t.ToString("x");
精彩评论