All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Binary coded decimal

Library to de- and encode binary coded decimals More...

Detailed Description

Library to de- and encode binary coded decimals

Files

file  bcd.h
 BCD definitions.
 

Functions

static uint8_t bcd_from_byte (uint8_t byte)
 Converts a byte to a binary coded decimal.
 
static uint8_t bcd_to_byte (uint8_t bcd)
 Converts a binary coded decimal to a byte.
 
int bcd_buf_from_u32 (uint32_t val, void *dst, size_t len)
 Convert a decimal value into a BCD buffer.
 

Function Documentation

◆ bcd_buf_from_u32()

int bcd_buf_from_u32 ( uint32_t val,
void * dst,
size_t len )

Convert a decimal value into a BCD buffer.

(This looks like the decimal integer value when printed as hex)

This will e.g. turn the value 123 -> 0x123 (decimal: 291)

Parameters
[in]valDecimal value to print
[out]dstDestination buffer
[in]lenSize of the destination buffer
Returns
number of bytes written
-ENOBUFS if dst is not large enough In that case the state of dst is undefined.

◆ bcd_from_byte()

static uint8_t bcd_from_byte ( uint8_t byte)
inlinestatic

Converts a byte to a binary coded decimal.

Parameters
[in]byteA byte
Returns
A binary coded decimal (4 MSB = 10s, 4 LSB = 1s)

Definition at line 37 of file bcd.h.

◆ bcd_to_byte()

static uint8_t bcd_to_byte ( uint8_t bcd)
inlinestatic

Converts a binary coded decimal to a byte.

Parameters
[in]bcdA binary coded decimal (4 MSB = 10, 4 LSB = 1s)
Returns
A byte

Definition at line 50 of file bcd.h.