Your task is to add code to this function in bcd.c: // given a BCD encoded...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 <stdio.h> #include <stdint.h> #include <stdlib.h> #include <assert.h> 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 <= 0x0909); int bcd value = = 1; printf("%d\n", bcd (bcd_value)); } return 0; } // given a BCD encoded value between 0 // return corresponding integer int bcd (int bcd_value) { return 0; : 99 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 <stdio.h> #include <stdint.h> #include <stdlib.h> #include <assert.h> 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 <= 0x0909); int bcd value = = 1; printf("%d\n", bcd (bcd_value)); } return 0; } // given a BCD encoded value between 0 // return corresponding integer int bcd (int bcd_value) { return 0; : 99
Expert Answer:
Answer rating: 100% (QA)
To convert a 2digit BinaryCoded Decimal BCD value to an integer you use bitwise operations ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Locate theory of constraints in contemporary management accounting. So, what do you think of its place? Your opinion? Why? Locate it within the context of other contemporary management accounting...
-
Your task is to modify the worked-example of ABC Wash Machine and print out the above statistical information. public class Clock { private int hr; //store hours private int min; //store minutes...
-
On Apr 5, 2021 Carter was in Omaha, Nebraska attending a seminar and was a guest at the Blue beiger Inn. At the end of the first day of the seminar, Carter took a swim in the motel's pool. Following...
-
Suppose we have an automatic module on the module path named lizard-^-cricket-^-1.0.0-SNAPSHOT.jar and no Automatic-Module-Name specified. What module name should named modules use to reference it?...
-
Let the random variables X and Y have the probability distributions listed in Table 15. Determine the probability distributions of the random variables in Exercises. 1. X2 2. Y2 3. X - 1 4. Y - 15 5....
-
Refer to the data provided in Exercise 17-19. Required: Prepare a pension spreadsheet to show the relationship among the PBO, plan assets, prior service cost, the net gain, pension expense, and the...
-
Trapan Retailing, Inc. has decided to diversify operations by selling through vending machines. Trapan plans on purchasing 312 vending machines to be placed in 78 different locations within one city,...
-
On January 2, 2011, Pet Corporation enters into a business combination with Sea Corporation in which Sea is dissolved. Pet pays $1,650,000 for Sea, the consideration consisting of 66,000 shares of...
-
Dain's Diamond Bit Drilling purchased the following assets this year. Asset Drill bits (5-year) Drill bits (5-year) Commercial building Purchase Date January 25 July 25 April 22 Original Basis $...
-
The following information, taken from the books of Herman Brothers Manufacturing represents the operations for January: The job cost system is used, and the February cost sheet for Job M45 shows the...
-
Discuss and elaborate with references the best mode of entry if Singapore International School want to expand its operation in Bali Indonesia.
-
Explain how sustainable marketing meets consumers needs
-
What four psychological factors influence a customers purchase behavior? Name and explain each of the four factors.
-
Explain the error in this interpretation of inflation data: In the 12-month period ending in December of 1980, consumer prices rose by 12.4 percentafter a 13.3 percent increase the year before....
-
What is marketing myopia? What are the short- and long-term implications for business in this situation?
-
Technological advances are perhaps the most dramatic forces affecting todays marketing strategies. Imagine you are in the marketing department of a major brand familiar to you. How might new...
-
If sin P=0.8142 and cos Q=0.4432 evaluate, correct to 3 decimal places: (a) sin(P-Q). (b) cos(P+Q) and (c) tan(P+Q), using the compound-angle formulae.
-
Evaluate the function at the given value(s) of the independent variable. Simplify the results. (x) = cos 2x (a) (0) (b) (- /4) (c) (/3) (d) ()
-
What statement would you use to print We have X varieties of cheese, where the current value of the cheeses variable replaces X?
-
Write a C++ program that requests and displays information as shown in the following example of output: What is your first name? Betty Sue What is your last name? Yewe What letter grade do you...
-
Suppose ted is a double variable. Declare a pointer that points to ted and use the pointer to display teds value.
-
Develop the following systems using the fairness pattern: 1. Tax fairness: A tax platform based on an ideal that aims to create a system of taxation that is fair, clear, and equivalent for all...
-
BOs make this pattern stable and extendible. Do you agree?
-
Write down some common case studies to highlight the importance of stable analysis patterns.
Study smarter with the SolutionInn App