Documentation ¶
Overview ¶
Package bcd provides conversions to and from BCD format.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode decodes a BCD encoded octet into the equivalent integer.
The lowest nibble is taken as being the most significant.
func DecodeSigned ¶
DecodeSigned decodes a BCD encoded octet where bit 3 of the msn indicates the sign of the encoded integer.
func Encode ¶
Encode converts an integer in the range 0..99 into two BCD digits.
The return value is the two BCD digits encoded into a byte in big endian, and any error detected during conversion.
func EncodeSigned ¶
EncodeSigned converts an integer in the range -79..79 into two BCD digits.
The return value is the two BCD digits encoded into a byte, with the most significant digit stored in the lowest nibble, and any error detected during conversion. If the integer is negative then bit 3 of the byte is set to 1 .
Types ¶
type ErrInvalidInteger ¶
type ErrInvalidInteger int
ErrInvalidInteger indicates that the integer is outside the range that can be encoded.
func (ErrInvalidInteger) Error ¶
func (e ErrInvalidInteger) Error() string
type ErrInvalidOctet ¶
type ErrInvalidOctet byte
ErrInvalidOctet indicates that at least one of the nibbles in the BCD octet is invalid, i.e. greater than 9.
For DecodeSigned only the upper (least significant) nibble can be invalid.
func (ErrInvalidOctet) Error ¶
func (e ErrInvalidOctet) Error() string