You can use Convert.ToString
to write out a value in a different base (Note that only certain bases are supported; 16 is one of them, see docs for details) :
int i = 16;
var str = Convert.ToString(i, 16);
سؤال
I have the following line in javascript:
c = Number(string_1.charCodeAt(i) ^ string_2.charCodeAt(u)).toString(16);
I need to rewrite it in c#, this is what I got so far:
string c = (Convert.ToChar(string_1[i]) ^ Convert.ToChar(string_2[u])).ToString(16);
I'm not able to enter radix value in ToString method. Any suggestions how I can do this? Thanks
المحلول
You can use Convert.ToString
to write out a value in a different base (Note that only certain bases are supported; 16 is one of them, see docs for details) :
int i = 16;
var str = Convert.ToString(i, 16);
نصائح أخرى
Just change it to .ToString("X");
which is the hexadecimal format specifier.
Or even easier, if you're looking for base 16 (aka hexadecimal):
int x = 12345 ;
string v = string.Format( "0x{0:X4}" , x ) ;
will give you
v = "0x3039"