Created
April 11, 2019 14:04
-
-
Save cstroie/3d49ed5898af0a95a33fd939647ca240 to your computer and use it in GitHub Desktop.
bin2bcd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint32_t bin2bcd(const uint16_t in) { | |
uint32_t out = 0; | |
for (uint8_t pos = 13; pos >= 0; pos--) { | |
if ((out & 0xF) >= 5) | |
out += 3; | |
if (((out & 0xF0) >> 4) >= 5) | |
out += (3 << 4); | |
if (((out & 0xF00) >> 8) >= 5) | |
out += (3 << 8); | |
out = (out << 1) | ((in >> pos) & 1); | |
} | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment