1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lozanna [386]
3 years ago
8

To reduce the number of used digital outputs of the microcontroller, the display board is connected to the main board through th

e 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.
Computers and Technology
1 answer:
Luda [366]3 years ago
7 0

Answer:

The program in Python is as follows:

BCD = ["0001","0010","0011","0100","0101","0110","0111"]

num = input("Decimal: ")

BCDValue = ""

valid = True

for i in range(len(num)):

   if num[i].isdigit():

       if(int(num[i])>= 0 and int(num[i])<8):

           BCDValue += BCD[i]+" "

       else:

           valid = False

           break;

   else:

       valid = False

       break;

if(valid):

   print(BCDValue)

else:

   print("Invalid")

Explanation:

This initializes the BCD corresponding value of the decimal number to a list

BCD = ["0001","0010","0011","0100","0101","0110","0111"]

This gets input for a decimal number

num = input("Decimal: ")

This initializes the required output (i.e. BCD value)  to an empty string

BCDValue = ""

This initializes valid input to True (Boolean)

valid = True

This iterates through the input string

for i in range(len(num)):

This checks if each character of the string is a number

   if num[i].isdigit():

If yes, it checks if the number ranges from 0 to 7 (inclusive)

       if(int(num[i])>= 0 and int(num[i])<8):

If yes, the corresponding BCD value is calculated

           BCDValue += BCD[i]+" "

       else:

If otherwise, then the input string is invalid and the loop is exited

<em>            valid = False</em>

<em>            break;</em>

If otherwise, then the input string is invalid and the loop is exited

<em>    else:</em>

<em>        valid = False</em>

<em>        break;</em>

If valid is True, then the BCD value is printed

<em>if(valid):</em>

<em>    print(BCDValue)</em>

If otherwise, it prints Invalid

<em>else:</em>

<em>    print("Invalid")</em>

You might be interested in
How do you organize texts and numerical data? ​
777dan777 [17]

Numerical data represent values that can be measured and put into a logical order. Examples of numerical data are height, weight, age, number of movies watched, IQ, etc.

3 0
2 years ago
What was the original intention for the creation of ARPANET?
Anika [276]

ARPANET was the network that became the 'basis' for the Internet. It was based on a concept first published in 1967. It was developed under the direction of the U.S. Advanced Research Projects Agency (ARPA). In 1969, the idea became a modest reality with the interconnection of four university computers.

3 0
3 years ago
Read 2 more answers
. Which of the following refers to the informal rules for how to behave online? A.
natta225 [31]

Answer:

D.netiquette

hope it is helpful to you

5 0
3 years ago
When should you integrate technology?​
earnstyle [38]
Nolur acil lütfen yalvarırım yalvarırım lütfen yalvarırım when should you integrate technology?
5 0
3 years ago
Read 2 more answers
Which of the following emergencies are weather-related? A. Ice storm B. Hurricane C. Earthquake D. A and B
Angelina_Jolie [31]

Answer:

The answer is D. A and B

Explanation:

I think the answer is D because Ice storms are caused by freezing rain and Hurricanes are formed near the equator over warm ocean waters. both of them are weather-related.

5 0
3 years ago
Read 2 more answers
Other questions:
  • What is a data mining??
    5·1 answer
  • You can access various sites on the WWW by using hyperlinks or by______. A. entering a key word for your search B. following dir
    12·2 answers
  • What is the keyboard shortcut used to paste previously copied text?
    15·2 answers
  • Please answer <br><br> Steps 1-6 <br><br> Visual basics
    7·1 answer
  • People are starting to type in whole questions rather than specific words, which leads credence to having _____ that have this a
    14·1 answer
  • When you pass an argument to a method, the argument's data type must be ____________ with the receiving parameter's data type?
    11·1 answer
  • If there are 18 people in your class and you want to divide the class into programming teams of 3
    7·1 answer
  • Which software programs should students avoid using to create and submit course work? (Choose all that apply). Word, Pages, Numb
    13·1 answer
  • What is the meaning of s used in 0 and 1 in computer .​
    8·1 answer
  • True or false: Quality score is an algorithm that scores each of your search ads on spelling and grammar.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!