c# 字符串转换为BCD编码
/// <summary> /// 字符串转换为BCD编码 /// </summary> /// <param name="strTemp">转换字符串</param> /// <returns>BCD编码</returns> private Byte[] convertFrom(string strTemp) { try { if (Convert.ToBoolean(strTemp.Length & 1))//数字的二进制码最后1位是1则为奇数 { strTemp = "0" + strTemp;//数位为奇数时前面补0 } Byte[] aryTemp = new Byte[strTemp.Length / 2]; for (int i = 0; i < (strTemp.Length / 2); i++) { aryTemp[i] = (Byte)(((strTemp[i * 2] - '0') << 4) | (strTemp[i * 2 + 1] - '0')); } return aryTemp;//高位在前 } catch { return null; } }