Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
3f95f9ed
Commit
3f95f9ed
authored
7 years ago
by
Martine Lenders
Browse files
Options
Downloads
Patches
Plain Diff
bcd: initial import of binary coded decimal en-/decoder
parent
d61be015
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sys/include/bcd.h
+60
-0
60 additions, 0 deletions
sys/include/bcd.h
with
60 additions
and
0 deletions
sys/include/bcd.h
0 → 100644
+
60
−
0
View file @
3f95f9ed
/*
* Copyright (C) 2017 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup sys_bcd Binary coded decimal
* @ingroup sys
* @brief Library to de- and encode binary coded decimals
* @{
*
* @file
* @brief BCD definitions
*
* @author Martine Lenders <m.lenders@fu-berlin.de>
*/
#ifndef BCD_H
#define BCD_H
#include
<stdint.h>
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* @brief Converts a byte to a binary coded decimal
*
* @param[in] byte A byte
*
* @return A binary coded decimal (4 MSB = 10s, 4 LSB = 1s)
*/
static
inline
uint8_t
bcd_from_byte
(
uint8_t
byte
)
{
/* ((byte / 10) << 4) | (byte % 10) */
return
byte
+
(
6
*
(
byte
/
10
));
}
/**
* @brief Converts a binary coded decimal to a byte
*
* @param[in] bcd A binary coded decimal (4 MSB = 10, 4 LSB = 1s)
*
* @return A byte
*/
static
inline
uint8_t
bcd_to_byte
(
uint8_t
bcd
)
{
/* == (10 * (bcd >> 4)) + (bcd & 0xf) */
return
bcd
-
(
6
*
(
bcd
>>
4
));
}
#ifdef __cplusplus
}
#endif
#endif
/* BCD_H */
/** @} */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment