Console.WriteLine("十六进制17的表示:" + Convert.ToInt32("17", 16));//即17是十六进制位 得到的结果是23 得到十进制数
将字符串转换成二进制
public static string mdFiveGet(string mdNum) { String BinOne = string.Empty; String BinAll = string.Empty; char[] nums = mdNum.ToCharArray(); for (int i = 0; i < nums.Length; i++) { string number = nums[i].ToString(); int num = Int32.Parse(number, System.Globalization.NumberStyles.HexNumber); BinOne = Convert.ToString(num, 2); BinAll = BinAll + BinOne; } Console.WriteLine("BIN:" + BinAll); return BinAll;
将字符串转换成字节流,字节流转换成字符串。
private static string _test = "1"; static void Main(string[] args) { string a = ""; byte[] bytes4 = Encoding.GetEncoding("GB2312").GetBytes(_test); string s4 = Encoding.GetEncoding("GB2312").GetString(bytes4); foreach (byte bt in bytes4) a += bt; Console.WriteLine("字节流为:" + a); Console.WriteLine("将字节流还原为字符串:" + s4); Console.ReadKey(); }
时间: 2024-10-23 05:13:36