Arduino-GPIO
General Purpose Input/Output (GPIO) library for Arduino
bcd.h
Go to the documentation of this file.
1 
19 #ifndef BCD_H
20 #define BCD_H
21 
25 struct bcd_t {
29  bcd_t() : m_value(0) {}
30 
35  bcd_t(uint8_t value)
36  {
37  uint8_t high = 0;
38  uint8_t low = value;
39  while (low > 9) {
40  high += 0x10;
41  low -= 10;
42  }
43  m_value = high + low;
44  }
45 
50  operator uint8_t()
51  {
52  uint8_t high = (m_value & 0xf0);
53  uint8_t low = (m_value & 0x0f);
54  return ((high >> 1) + (high >> 3) + low);
55  }
56 
57 private:
58  uint8_t m_value;
59 } __attribute__((packed));
60 
61 
62 #endif
bcd_t()
Definition: bcd.h:29
bcd_t(uint8_t value)
Definition: bcd.h:35
Definition: bcd.h:25