c# string to hex , hex to byte conversion

扶醉桌前 提交于 2019-12-30 08:37:09

问题


I have a method which takes a hex value and assign it as a plaintext but type of byte like that

byte plainText = 0xd7;

I want to take this value from textbox ,for exmaple the user will type d7 to textbox and ı will assign it like

byte plaintText = 0xd7

I could not achive that.


回答1:


You can use the Convert.ToByte(String, Int32) method with the base set to 16 (hexadecimal):

String text = "d7";
byte value = Convert.ToByte(text, 16);    



回答2:


Try this:

var myByte = Byte.Parse("d7", NumberStyles.HexNumber)



回答3:


have you tried to use this?

Byte.parse



来源:https://stackoverflow.com/questions/8576296/c-sharp-string-to-hex-hex-to-byte-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!