Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting to hex?

Tags:

c#

hex

Whenever I try to convert '™' to hex string using

string.Format("{0:X}", (int)"™");

It returns 2122 which is weird because when I use online converters I get 99. Why?

like image 436
method Avatar asked Jul 04 '26 07:07

method


2 Answers

99 is the code for ™ in the Windows-1252 encoding, while 2122 is the code according to the Unicode standard.

like image 147
Cito Avatar answered Jul 06 '26 20:07

Cito


As explained by Cito, 99 is the code for ™ in the Windows-1252 encoding. You can get it as follows:

var result = Encoding.GetEncoding("Windows-1252")
                     .GetBytes("™")
                     .Single()
                     .ToString("X");

// result == "99"
like image 38
dtb Avatar answered Jul 06 '26 21:07

dtb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!