fork(156) download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.  
  5. int binaryInput = 0x202;
  6. int bcdResult = 0;
  7. int shift = 0;
  8.  
  9. printf("Binary: 0x%x (dec: %d)\n", binaryInput , binaryInput );
  10.  
  11. while (binaryInput > 0) {
  12. bcdResult |= (binaryInput % 10) << (shift++ << 2);
  13. binaryInput /= 10;
  14. }
  15.  
  16. printf("BCD: 0x%x (dec: %d)\n", bcdResult , bcdResult );
  17. return 0;
  18. }
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
Binary: 0x202 (dec: 514)
BCD: 0x514 (dec: 1300)