summaryrefslogtreecommitdiffstats
path: root/src/include/bcd.h
blob: ebb6e02d60d3d575addea309f2abc31e11e2d7dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* SPDX-License-Identifier: GPL-2.0-only */
/* This file is part of the coreboot project. */

#ifndef _BCD_H_
#define _BCD_H_

#include <stdint.h>

static inline uint8_t bcd2bin(uint8_t val)
{
	return ((val >> 4) & 0xf) * 10 + (val & 0xf);
}

static inline uint8_t bin2bcd(uint8_t val)
{
	return ((val / 10) << 4) | (val % 10);
}

#endif /* _BCD_H_ */