bcd

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2020 License: MIT Imports: 1 Imported by: 1

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

func Decode(bcd byte) (int, error)

Decode decodes a BCD encoded octet into the equivalent integer.

The lowest nibble is taken as being the most significant.

func DecodeSigned

func DecodeSigned(bcd byte) (int, error)

DecodeSigned decodes a BCD encoded octet where bit 3 of the msn indicates the sign of the encoded integer.

func Encode

func Encode(u int) (byte, error)

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

func EncodeSigned(s int) (byte, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL