Library to de- and encode binary coded decimals.  
More...
Library to de- and encode binary coded decimals. 
 | 
| file   | bcd.h | 
|   | BCD definitions. 
  | 
|   | 
 | 
| static uint8_t  | bcd_from_byte (uint8_t byte) | 
|   | Converts a byte to a binary coded decimal.  More...
  | 
|   | 
| static uint8_t  | bcd_to_byte (uint8_t bcd) | 
|   | Converts a binary coded decimal to a byte.  More...
  | 
|   | 
| int  | bcd_buf_from_u32 (uint32_t val, void *dst, size_t len) | 
|   | Convert a decimal value into a BCD buffer.  More...
  | 
|   | 
| uint32_t  | bcd_buf_to_u32 (const void *src, size_t len) | 
|   | Convert a BCD buffer into it's binary representation (This will reverse bcd_buf_from_u32)  More...
  | 
|   | 
| uint64_t  | bcd_buf_to_u64 (const void *src, size_t len) | 
|   | Convert a BCD buffer into it's binary representation.  More...
  | 
|   | 
| int  | bcd_buf_from_str (const char *str, size_t str_len, void *dst, size_t dst_len) | 
|   | Convert a string into a BCD buffer Digits may be separated by any character.  More...
  | 
|   | 
◆ bcd_buf_from_str()
      
        
          | int bcd_buf_from_str  | 
          ( | 
          const char *  | 
          str,  | 
        
        
           | 
           | 
          size_t  | 
          str_len,  | 
        
        
           | 
           | 
          void *  | 
          dst,  | 
        
        
           | 
           | 
          size_t  | 
          dst_len  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Convert a string into a BCD buffer Digits may be separated by any character. 
- Parameters
 - 
  
    | [in] | str | Input string  | 
    | [in] | str_len | Length of the input string  | 
    | [out] | dst | Destination buffer  | 
    | [in] | dst_len | Size of the destination buffer | 
  
   
- Returns
 - number of bytes written 
 
- Return values
 - 
  
    | -ENOBUFS | if dst is not large enough In that case the state of dst is undefined.  | 
  
   
 
 
◆ 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] | val | Decimal value to print  | 
    | [out] | dst | Destination buffer  | 
    | [in] | len | Size of the destination buffer | 
  
   
- Returns
 - number of bytes written 
 
- Return values
 - 
  
    | -ENOBUFS | if dst is not large enough In that case the state of dst is undefined.  | 
  
   
 
 
◆ bcd_buf_to_u32()
      
        
          | uint32_t bcd_buf_to_u32  | 
          ( | 
          const void *  | 
          src,  | 
        
        
           | 
           | 
          size_t  | 
          len  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Convert a BCD buffer into it's binary representation (This will reverse bcd_buf_from_u32) 
- Parameters
 - 
  
    | [in] | src | The BCD buffer to convert  | 
    | [in] | len | Bytes in src  | 
  
   
- Returns
 - decimal representation of 
src  
 
 
◆ bcd_buf_to_u64()
      
        
          | uint64_t bcd_buf_to_u64  | 
          ( | 
          const void *  | 
          src,  | 
        
        
           | 
           | 
          size_t  | 
          len  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Convert a BCD buffer into it's binary representation. 
- Parameters
 - 
  
    | [in] | src | The BCD buffer to convert  | 
    | [in] | len | Bytes in src  | 
  
   
- Returns
 - decimal representation of 
src  
 
 
◆ bcd_from_byte()
  
  
      
        
          | static uint8_t bcd_from_byte  | 
          ( | 
          uint8_t  | 
          byte | ) | 
           | 
         
       
   | 
  
inlinestatic   | 
  
 
Converts a byte to a binary coded decimal. 
- Parameters
 - 
  
  
 
- Returns
 - A binary coded decimal (4 MSB = 10s, 4 LSB = 1s) 
 
Definition at line 39 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] | bcd | A binary coded decimal (4 MSB = 10, 4 LSB = 1s) | 
  
   
- Returns
 - A byte 
 
Definition at line 52 of file bcd.h.