string s = "080003005844967d"; byte[] b = new byte[s.Length / 2] for (int i = 0; i < s.Length; i += 2) b[i / 2] = Convert.ToByte("0x" + s.SubString(i, 2));
用这个 Convert.ToByte static void Main(string[] args) { string str = @"080003005844967d"; List<byte> bytes = new List<byte>(); for (int i = 0; i < str.Length; i += 2) { string strTemp = str.Substring(i, 2); byte b = Convert.ToByte(strTemp, 16); bytes.Add(b); } byte[] result = bytes.ToArray(); foreach (byte b in result) { Console.WriteLine("0x"+string.Format("{0:X}", b).PadLeft(2, '0')); } }
byte[] b = new byte[s.Length / 2]
for (int i = 0; i < s.Length; i += 2)
b[i / 2] = Convert.ToByte("0x" + s.SubString(i, 2));
Convert.ToByte
static void Main(string[] args)
{
string str = @"080003005844967d";
List<byte> bytes = new List<byte>();
for (int i = 0; i < str.Length; i += 2) {
string strTemp = str.Substring(i, 2);
byte b = Convert.ToByte(strTemp, 16);
bytes.Add(b);
}
byte[] result = bytes.ToArray();
foreach (byte b in result) {
Console.WriteLine("0x"+string.Format("{0:X}", b).PadLeft(2, '0'));
}
}
char[] b=convert.tochararray(a);
byte[] c=Encoding.Default.GetBytes(b);