Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <iostream>
- #pragma hdrstop
- using namespace std;
- uint8_t dec2bcd(uint8_t);
- uint8_t bcd2dec(uint8_t);
- //---------------------------------------------------------------------------
- #pragma argsused
- int main(int argc, char* argv[])
- {
- cout << "Dec : BCD" << "\n";
- for (uint8_t i = 10; i < 100; i++) {
- cout << (int)i << " : " << (int)dec2bcd(i) << "\n";
- }
- cout << "-> " << (int)bcd2dec(0x81) << "\n";
- return 0;
- }
- //---------------------------------------------------------------------------
- // Convert Decimal to BCD
- uint8_t dec2bcd(uint8_t num)
- {
- return ((num / 10 * 16) + (num & 10));
- }
- // Convert BCD to Decimal
- uint8_t bcd2dec(uint8_t num)
- {
- return ((num / 16 * 10) + (num % 16));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement