问题
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