1. Convert an object to a byte object
public static byte GetByte(object o) { byte retInt = 0; if (o != null) { byte tmp; if ((().Trim(), out tmp)) { retInt = tmp; } } return retInt; }
2. Convert a hexadecimal string to a byte object, the string starts with 0x
public static byte GetByteFormHex(string hexValue) { try { return (hexValue, 16); } catch { return 0; } }
3. Convert a single character to a byte object
public static byte GetByteFormSingleString(string value) { return GetByteFormChar((value)); }
4. Convert a string to a byte array
public static byte[] GetBytes(string values) { return (values); }
The above content is the functions related to Byte conversion in C# introduced to you by the editor. I hope it will be helpful to you!