/// <summary> /// 二进制转换为十六进制 /// </summary> /// <param name="b"></param> /// <returns></returns> public static string Binary2Hex(string b) { b = Mathr.TrimZero(b); string[] s = b.Split('.'); string i = s[0]; string output = ""; int il = (int)Math.Ceiling(i.Length / 4f) * 4; i = i.PadLeft(il, '0'); for (int ii = 0; ii < il; ii += 4) { output += SignBinary2Hex(i.Substring(ii, 4)); } if (s.Length > 1) { output += "."; string f = s[1]; int fl = (int)Math.Ceiling(f.Length / 4f) * 4; f = f.PadRight(fl, '0'); for (int fi = 0; fi < fl; fi += 4) { output += SignBinary2Hex(f.Substring(fi, 4)); } } return(output); }
/// <summary> /// 八进制转换为二进制 /// </summary> /// <returns></returns> public static string Octal2Binary(string o) { o = Mathr.TrimZero(o); string output = ""; for (int i = 0, l = o.Length; i < l; i++) { output += SignOctal2Binary(o[i]); } output = Mathr.TrimZero(output); return(output); }