+ buf := make([]byte, len(str)/2+len(str)%2)
+ for i := 0; i < len(str); i++ {
+ var schar int = bcd.index(str[i])
+ if schar < 0 {
+ return nil
+ }
+ if i%2 > 0 {
+ buf[i/2] &= 0xf0
+ buf[i/2] |= ((uint8)(schar) & 0x0f)
+ } else {
+ buf[i/2] = 0x0f | (uint8)(schar)<<4
+ }
+
+ }
+ return buf
+}
+
+func (bcd *Bcd) Decode(buf []byte) string {
+ var strbytes []byte
+ for i := 0; i < len(buf); i++ {
+ var b byte
+
+ b = bcd.byte(int(buf[i] >> 4))
+ //if b == '?' {
+ // return ""
+ //}
+ strbytes = append(strbytes, b)
+
+ b = bcd.byte(int(buf[i] & 0x0f))
+ //if b == '?' {
+ // return ""
+ //}
+ strbytes = append(strbytes, b)
+ }
+ return string(strbytes)
+}
+
+//-----------------------------------------------------------------------------
+//
+// 5 digit example
+// String format : D1D2D3D4D5
+// TBCD Coded format: 0xD2D1 0xD4D3 0x0fD5
+// String format : D1D2D3D4D5F
+//
+// 6 digit example
+// String format : D1D2D3D4D5
+// TBCD Coded format: 0xD2D1 0xD4D3 0xD6D5
+// String format : D1D2D3D4D5D6
+//
+//-----------------------------------------------------------------------------
+type Tbcd struct {
+ bcdbase
+}
+
+func (bcd *Tbcd) Encode(str string) []byte {