我需要一些帮助,如何将以下内容转换为字节。
string s = "0x01";
byte b = Convert.toByte(s); //(Tried this) ??
byte c = byte.Parse(s); //(Tried this as well)
如何将s转换为字节?
我想解析函数将不允许在字符串中使用前缀0X,因此您可以使用子字符串将其删除。
byte myByte = Byte.Parse(s.SubString(2), NumberStyles.HexNumber);
或使用-
byte myByte = Convert.ToByte(s,16);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句