COSA
An Object-Oriented Platform for Arduino Programming
BCD.h
Go to the documentation of this file.
1 
30 #ifndef COSA_BCD_H
31 #define COSA_BCD_H
32 
33 #include "Cosa/Types.h"
34 
40 inline uint8_t to_binary(uint8_t value) __attribute__((always_inline));
41 inline uint8_t
42 to_binary(uint8_t value)
43 {
44  uint8_t high = (value >> 4);
45  uint8_t low = (value & 0x0f);
46  return ((high << 3) + (high << 1) + low);
47 }
48 
54 inline uint8_t to_bcd(uint8_t value) __attribute__((always_inline));
55 inline uint8_t
56 to_bcd(uint8_t value)
57 {
58  uint8_t res = 0;
59  while (value > 9) {
60  res += 0x10;
61  value -= 10;
62  }
63  return (res + value);
64 }
65 
71 inline void
72 to_binary(uint8_t* buf, size_t size)
73 {
74  for (uint8_t i = 0; i < size; i++)
75  buf[i] = to_binary(buf[i]);
76 }
77 
83 inline void
84 to_bcd(uint8_t* buf, size_t size)
85 {
86  for (uint8_t i = 0; i < size; i++)
87  buf[i] = to_bcd(buf[i]);
88 }
89 
90 #endif
91 
uint8_t to_binary(uint8_t value)
Definition: BCD.h:42
uint8_t to_bcd(uint8_t value)
Definition: BCD.h:56