/// <summary> /// 将数字形式的字符串转换为BCD /// </summary> /// <param name="str"></param> /// <returns></returns> public static byte[] GetBytes(string str) { if (str == null || str == string.Empty) { throw new ArgumentException("string is null"); } if (str.Length % 2 == 1) { str = "0" + str; } byte[] buf = new byte[str.Length / 2]; for (int i = 0; i < buf.Length; i++) { int num = int.Parse(str.Substring(i * 2, 2)); buf[i] = BCDCoder.GetBytes(num, 1)[0]; } return(buf); }
public static DateTime GetDateTime(byte[] buf) { return(GetDateTime(BCDCoder.GetString(buf))); }
/// <summary> /// BCD形式的byte数组转换成字符串 /// </summary> /// <param name="byteArray"></param> /// <returns></returns> public static string GetString(byte[] byteArray) { return(BCDCoder.GetString(byteArray, 0, byteArray.Length)); }