bcd.h 548 B

1234567891011121314151617181920
  1. /* Permission is hereby granted to copy, modify and redistribute this code
  2. * in terms of the GNU Library General Public License, Version 2 or later,
  3. * at your option.
  4. */
  5. /* macros to translate to/from binary and binary-coded decimal (frequently
  6. * found in RTC chips).
  7. */
  8. #ifndef _BCD_H
  9. #define _BCD_H
  10. #define BCD2BIN(val) (((val) & 0x0f) + ((val)>>4)*10)
  11. #define BIN2BCD(val) ((((val)/10)<<4) + (val)%10)
  12. /* backwards compat */
  13. #define BCD_TO_BIN(val) ((val)=BCD2BIN(val))
  14. #define BIN_TO_BCD(val) ((val)=BIN2BCD(val))
  15. #endif /* _BCD_H */