문제

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"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top