]> cloudbase.mooo.com Git - z180-stamp.git/blob - avr/bcd.c
Server: Time and Date support
[z180-stamp.git] / avr / bcd.c
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
11 uint_fast8_t bcd2bin(uint8_t val)
12 {
13 return (val >> 4) * 10 + (val & 0x0f);
14 }
15
16 uint8_t bin2bcd (uint_fast8_t val)
17 {
18 div_t d = div(val, 10);
19
20 return (d.quot << 4) | d.rem;
21 }