十六进制与十进制,整数互转
//十六进制byte数组转为 int 十进制 byte[] d1 = new byte[4] {0x34,0xFB,0x5E,0x38 }; if (BitConverter.IsLittleEndian) Array.Reverse(d1); //need the bytes in the reverse order int value = BitConverter.ToInt32(d1, 0); ///十六进制数字字符串转为int 十进制 int va = Convert.ToInt32("34FB5E38", 16);
十六进制与字符串互转:
public static byte[] StringToBytes(string TheString) { Encoding FromEcoding = Encoding.GetEncoding("UTF-8"); Encoding ToEcoding = Encoding.GetEncoding("GB2312"); byte[] FromBytes = FromEcoding.GetBytes(TheString); byte[] ToBytes = Encoding.Convert(FromEcoding, ToEcoding, FromBytes); return ToBytes; } public static string BytesToString(byte[] Bytes) { string Mystring; Encoding FromEcoding = Encoding.GetEncoding("GB2312"); Encoding ToEcoding = Encoding.GetEncoding("UTF-8"); byte[] ToBytes = Encoding.Convert(FromEcoding, ToEcoding, Bytes); Mystring = ToEcoding.GetString(ToBytes); return Mystring; }
标签:十六进制,Encoding,c#,FromEcoding,byte,十进制,ToEcoding From: https://www.cnblogs.com/sishahu/p/17764036.html