C# Convert Char to Byte (Hex representation)

后端 未结 5 1265
半阙折子戏
半阙折子戏 2021-02-07 00:23

This seems to be an easy problem but i can\'t figure out.

I need to convert this character < in byte(hex representation), but if i use



        
5条回答
  •  误落风尘
    2021-02-07 00:49

    You want to convert the numeric value to hex using ToString("x"):

    string asHex = b.ToString("x");
    

    However, be aware that you code to convert the "<" character to a byte will work for that particular character, but it won't work for non-ANSI characters (that won't fit in a byte).

提交回复
热议问题