#include <stdio.h>
int main(void) {
int binaryInput = 0x202;
int bcdResult = 0;
int shift = 0;
printf("Binary: 0x%x (dec: %d)\n", binaryInput
, binaryInput
);
while (binaryInput > 0) {
bcdResult |= (binaryInput % 10) << (shift++ << 2);
binaryInput /= 10;
}
printf("BCD: 0x%x (dec: %d)\n", bcdResult
, bcdResult
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CgogICBpbnQgYmluYXJ5SW5wdXQgPSAweDIwMjsgCiAgIGludCBiY2RSZXN1bHQgPSAwOwogICBpbnQgc2hpZnQgPSAwOwoKICAgcHJpbnRmKCJCaW5hcnk6IDB4JXggKGRlYzogJWQpXG4iLCBiaW5hcnlJbnB1dCAsIGJpbmFyeUlucHV0ICk7CgogICB3aGlsZSAoYmluYXJ5SW5wdXQgPiAwKSB7CiAgICAgIGJjZFJlc3VsdCB8PSAoYmluYXJ5SW5wdXQgJSAxMCkgPDwgKHNoaWZ0KysgPDwgMik7CiAgICAgIGJpbmFyeUlucHV0IC89IDEwOwogICB9CgogICBwcmludGYoIkJDRDogMHgleCAoZGVjOiAlZClcbiIsIGJjZFJlc3VsdCAsIGJjZFJlc3VsdCApOwogICByZXR1cm4gMDsKfQ==