Toggle navigation
Documentation
The friendly Operating System for the Internet of Things
Loading...
Searching...
No Matches
bcd.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2017 Freie Universität Berlin
3
*
4
* This file is subject to the terms and conditions of the GNU Lesser
5
* General Public License v2.1. See the file LICENSE in the top level
6
* directory for more details.
7
*/
8
20
#ifndef BCD_H
21
#define BCD_H
22
23
#include <stdint.h>
24
25
#ifdef __cplusplus
26
extern
"C"
{
27
#endif
28
36
static
inline
uint8_t
bcd_from_byte
(uint8_t
byte
)
37
{
38
/* ((byte / 10) << 4) | (byte % 10) */
39
return
byte
+ (6 * (
byte
/ 10));
40
}
41
49
static
inline
uint8_t
bcd_to_byte
(uint8_t bcd)
50
{
51
/* == (10 * (bcd >> 4)) + (bcd & 0xf) */
52
return
bcd - (6 * (bcd >> 4));
53
}
54
55
#ifdef __cplusplus
56
}
57
#endif
58
59
#endif
/* BCD_H */
bcd_to_byte
static uint8_t bcd_to_byte(uint8_t bcd)
Converts a binary coded decimal to a byte.
Definition
bcd.h:49
bcd_from_byte
static uint8_t bcd_from_byte(uint8_t byte)
Converts a byte to a binary coded decimal.
Definition
bcd.h:36
Generated on Sat Nov 23 2024 01:58:07 by
1.9.8