C# Convert Char to Byte (Hex representation)

后端 未结 5 1271
半阙折子戏
半阙折子戏 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 01:07

    You could use the BitConverter.ToString method to convert a byte array to hexadecimal string:

    string hex = BitConverter.ToString(new byte[] { Convert.ToByte('<') });
    

    or simply:

    string hex = Convert.ToByte('<').ToString("x2");
    

提交回复
热议问题