Ask Question
12 June, 17:08

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.

+3
Answers (1)
  1. 12 June, 19:04
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers