|
@@ -0,0 +1,26 @@
|
|
|
+/*
|
|
|
+ * SPDX-FileCopyrightText: 2022 Helmut Pozimski <helmut@pozimski.eu>
|
|
|
+ *
|
|
|
+ * SPDX-License-Identifier: GPL-2.0-only
|
|
|
+ */
|
|
|
+
|
|
|
+#include <stdint.h>
|
|
|
+
|
|
|
+uint8_t bcd_first_digit_value_bin(uint8_t bcd_value) {
|
|
|
+ return (((bcd_value & 0xF0) >> 4)) * 10;
|
|
|
+}
|
|
|
+
|
|
|
+uint8_t bcd_last_digit_value_bin(uint8_t bcd_value) {
|
|
|
+ return bcd_value & 0x0F;
|
|
|
+}
|
|
|
+
|
|
|
+uint8_t bcd2bin(uint8_t bcd_value) {
|
|
|
+ return bcd_last_digit_value_bin(bcd_value) + bcd_first_digit_value_bin(bcd_value);
|
|
|
+}
|
|
|
+
|
|
|
+uint8_t bin2bcd(uint8_t bin_value) {
|
|
|
+ uint8_t second_digit = (bin_value / 10) << 4;
|
|
|
+ uint8_t first_digit = bin_value % 10;
|
|
|
+ return first_digit + second_digit;
|
|
|
+}
|
|
|
+
|