Question: Your task is to add code to this function in bcd.c: // given a BCD encoded value between 0 // return corresponding integer int

Your task is to add code to this function in bcd.c: // given a BCD encoded value between 0 // return corresponding integer int bcd (int bcd_value) { } // PUT YOUR CODE HERE return 0; Add code to the function bcd so that, given a 2 digit Binary-Coded Decimal (BCD) value, it returns the corresponding integer. $ ./bcd 0x07 7 $ ./bcd 0x0102 12 In binary-coded decimal format, each byte holds 1 decimal value (0 to 9), so each byte contains 1 decimal digit. For example: $ ./bcd 0x0402 42 HINT: II # note: 0x0102 NOTE: # note: 0x0402 99 == == 258 decimal 1026 decimal Use the bitwise operators & and >> to extract each BCD digit. bcd should return an integer value between 0 and 99 inclusive. You may define and call your own functions if you wish. You are not permitted to call any functions from the C library. You are not permitted to change the main function you have been given, or to change bcd 's prototype (its return type and argument types). #include #include #include #include int bcd (int bcd_value); int main(int argc, char *argv[]) { for (int arg = 1; arg < argc; arg++) { long 1 = strtol (argv[arg], NULL, 0); assert (1 >= 0 && 1
Step by Step Solution
There are 3 Steps involved in it
To convert a 2digit BinaryCoded Decimal BCD value to an integer you use bitwise operations ... View full answer
Get step-by-step solutions from verified subject matter experts
