]> cloudbase.mooo.com Git - z180-stamp.git/blame - avr/bcd.c
cli.c bugfix: Comment only lines are not an error.
[z180-stamp.git] / avr / bcd.c
CommitLineData
845cbdbd
L
1/*
2 * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include "stdlib.h"
8#include "stdint.h"
9#include "bcd.h"
10
11uint_fast8_t bcd2bin(uint8_t val)
12{
13 return (val >> 4) * 10 + (val & 0x0f);
14}
15
16uint8_t bin2bcd (uint_fast8_t val)
17{
18 div_t d = div(val, 10);
19
20 return (d.quot << 4) | d.rem;
21}