[英]c# string to hex , hex to byte conversion
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 我想从文本框中获取此值,例如,用户将d7键入文本框,ı将分配给它
byte plaintText = 0xd7
I could not achive that. 我无法实现这一点。
You can use the Convert.ToByte(String, Int32)
method with the base set to 16 (hexadecimal): 您可以使用
Convert.ToByte(String, Int32)
方法,并将基数设置为16(十六进制):
String text = "d7";
byte value = Convert.ToByte(text, 16);
尝试这个:
var myByte = Byte.Parse("d7", NumberStyles.HexNumber)
你试过用这个吗?
Byte.parse
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.