字符串和BCD码转换
private string BCDToString(byte bts) { try { string bs = (bts >> 4).ToString() + (((byte)(bts << 4)) >> 4).ToString(); return bs; } catch (Exception ex) { throw ex; } }
private byte StringToBCD(string str) { int x = int.Parse(str.Substring(0, 1)); int y = int.Parse(str.Substring(1, 1)); byte xx = Convert.ToByte(x); byte yy = Convert.ToByte(y); byte by = Convert.ToByte(((byte)xx << 4) + ((byte)yy)); return by; }