Ask Question
8 July, 08:44

Imagine that you are prototyping an electronic device based on the Arduino platform and you are using a seven-segment display to show numeric values. To reduce the number of used digital outputs of the microcontroller, the display board is connected to the main board through the integrated circuit of the decoder, which converts binary coded decimal (BCD) values to signals for the seven-segment display. So, to show any number on the display you need to set the required BCD code on the microcontroller's outputs. Write a program to convert an integer number represented as a string to a BCD code required for the display. In the BCD code, every decimal digit is encoded with its four-bit binary value. Encoding all digits of the decimal number and concatenating the resulting codes into one string you will get a resulting BCD code. A space is used to separate digits in the BCD code and make it more readable. For example, a number 173 will be encoded to BCD as 0001 0111 0011.

+1
Answers (1)
  1. 8 July, 12:43
    0
    We can write this program (to convert an integer number represented as string to BCD code) in C+ + as;

    Integer number (string) to BCD code using C++

    #include

    #include

    using namespace std;

    int binaryToDecimal (string n)

    {

    string num = n;

    int dec_value = 0;

    int base = 1; / / Initializing base value to 1, i. e 2^0

    int len = num. length ();

    for (int i = len - 1; i > = 0; i--) {

    if (num[i] = = '1')

    dec_value + = base;

    base = base * 2;

    }

    return dec_value;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Imagine that you are prototyping an electronic device based on the Arduino platform and you are using a seven-segment display to show ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers