Expand description
§BCD (Binary Coded Decimal) conversion utilities for RTC operations
This module provides conversion functions between BCD and decimal formats commonly used in Real-Time Clock (RTC) chips like the DS1307.
§BCD Format Overview
Binary Coded Decimal (BCD) represents decimal digits using 4-bit binary patterns:
- Each decimal digit (0-9) is encoded in 4 bits
- One byte can hold two decimal digits (00-99)
- High nibble = tens digit, low nibble = ones digit
§Format Examples
| Decimal | BCD Binary | BCD Hex |
|---|---|---|
| 00 | 0000 0000 | 0x00 |
| 01 | 0000 0001 | 0x01 |
| 09 | 0000 1001 | 0x09 |
| 10 | 0001 0000 | 0x10 |
| 23 | 0010 0011 | 0x23 |
| 59 | 0101 1001 | 0x59 |
| 99 | 1001 1001 | 0x99 |
Functions§
- from_
decimal - Convert decimal byte to BCD encoding
- to_
decimal - Convert a BCD encoded byte to decimal First 4 bits are tens of the number Last 4 bits are ones of the number