Convert from int to hex

I want to convert some ints to hex, but I get 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 use it in the form of a window, not in the console.

+4
source share
6 answers

To convert a number to hex just use:

 integerValue.ToString("X") 
+9
source

Why are you using encryption if all you want to do is convert?

Use this snippet for actual conversion

 int myNumber = 42; String myHexNumber = myNumber.ToString("X"); 
+5
source
 value.ToString("X") is all you need 
+3
source
 int t = 12345; Console.WriteLine("{0:X4}", t); 

no?

+3
source

use Convert.ToString(intValue, 16);

Edit: this method can be used in all databases, such as Convert.ToString(intValue, 2)

+2
source

It looks like you want to convert int to the sixth line.

 int t = 12345; string hex = t.ToString("x"); 
+2
source

Source: https://habr.com/ru/post/1334003/


All Articles