3. One can build a circuit which consists of a hierarchy of logic gates which take a series of 2" bits as input. The bits are processed in stages. The first stage pairs all the bits from the input and applies a logic operation to each pair, leaving 2n-1 bits for the next level. The process is repeated at each subsequent level until only 1 bit remains. Write a program to aid in the design of this circuit that will determine for a given set of input bits and a given logic gate layout, what the output bit will be. Below is a description of each type of logic gate that the circuit can consist of: • AND GATE-Outputs a 1 if both bits are 1, outputs O otherwise. OR GATE-Outputs a 1 if at least one of the bits is 1, outputs 0 otherwise.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter4: Making Decisions
Section: Chapter Questions
Problem 4RQ
icon
Related questions
Question

C++ 

 

Sample Run:

Enter file name: gates.txt

Set 1: 1
Set 2: 0

Below is a schematic of a possible circuit that could be input into the program. It corresponds to the
second data set in the sample input:
·
1
0
Sample File:
2
2
11
A
8
1 0 0 1 1 1 0 0
AARRXA X
0
A
1 -
1
A
1 -
0
R-
0
0 -
0
1
XI - 0
A|- 0
|
R - 0 -
Input will be from a data file. The first line of input will contain an integer number indicating how many
data sets are to be processed. The remaining lines will contain the data sets. Each data set will consist of
three lines formatted according to the following descriptions:
Bit Count - An integer corresponding to the number of bits being fed into the circuit. This
integer will be a number between 2 and 32 and will be a power of 2.
Bit List - A space separated list of bits (either 0 or 1) that will be fed into the circuit.
Gate List - A space separated list of logic gates. The first n/2¹ gates constitute the first stage and
operate directly on the input bits, the next n/2² gates constitute the second stage and operate
on the results from the first stage, and so on for the other stages until only one gate remains.
(Note, it is possible the there is only one stage) Each character in the list will either be 'A', 'R',
or 'X' (corresponding to AND, OR, or XOR gates respectively). There will be exactly n-1 logic gates
(where n is the number of bits read in).
XI - 0
Output to the screen the bit (0 or 1) resulting from the logic gate operations on the input bits, properly
labeled. Each pair of bits will be fed into the first n/2¹ gates, and the results of each of those operations
will be fed into the next n/2² gates, and so on until the result is reduced to a single bit (0 or 1). Let the
user input the file name from the keyboard. Refer to the sample output below.
Transcribed Image Text:Below is a schematic of a possible circuit that could be input into the program. It corresponds to the second data set in the sample input: · 1 0 Sample File: 2 2 11 A 8 1 0 0 1 1 1 0 0 AARRXA X 0 A 1 - 1 A 1 - 0 R- 0 0 - 0 1 XI - 0 A|- 0 | R - 0 - Input will be from a data file. The first line of input will contain an integer number indicating how many data sets are to be processed. The remaining lines will contain the data sets. Each data set will consist of three lines formatted according to the following descriptions: Bit Count - An integer corresponding to the number of bits being fed into the circuit. This integer will be a number between 2 and 32 and will be a power of 2. Bit List - A space separated list of bits (either 0 or 1) that will be fed into the circuit. Gate List - A space separated list of logic gates. The first n/2¹ gates constitute the first stage and operate directly on the input bits, the next n/2² gates constitute the second stage and operate on the results from the first stage, and so on for the other stages until only one gate remains. (Note, it is possible the there is only one stage) Each character in the list will either be 'A', 'R', or 'X' (corresponding to AND, OR, or XOR gates respectively). There will be exactly n-1 logic gates (where n is the number of bits read in). XI - 0 Output to the screen the bit (0 or 1) resulting from the logic gate operations on the input bits, properly labeled. Each pair of bits will be fed into the first n/2¹ gates, and the results of each of those operations will be fed into the next n/2² gates, and so on until the result is reduced to a single bit (0 or 1). Let the user input the file name from the keyboard. Refer to the sample output below.
3. One can build a circuit which consists of a hierarchy of logic gates which take a series of 2" bits as
input. The bits are processed in stages. The first stage pairs all the bits from the input and applies a logic
operation to each pair, leaving 2-1 bits for the next level. The process is repeated at each subsequent
level until only 1 bit remains. Write a program to aid in the design of this circuit that will determine for a
given set of input bits and a given logic gate layout, what the output bit will be. Below is a description of
each type of logic gate that the circuit can consist of:
• AND GATE - Outputs a 1 if both bits are 1, outputs O otherwise.
•
OR GATE-Outputs a 1 if at least one of the bits is 1, outputs 0 otherwise.
XOR GATE-Outputs O if both bits are equal, outputs 1 otherwise.
Transcribed Image Text:3. One can build a circuit which consists of a hierarchy of logic gates which take a series of 2" bits as input. The bits are processed in stages. The first stage pairs all the bits from the input and applies a logic operation to each pair, leaving 2-1 bits for the next level. The process is repeated at each subsequent level until only 1 bit remains. Write a program to aid in the design of this circuit that will determine for a given set of input bits and a given logic gate layout, what the output bit will be. Below is a description of each type of logic gate that the circuit can consist of: • AND GATE - Outputs a 1 if both bits are 1, outputs O otherwise. • OR GATE-Outputs a 1 if at least one of the bits is 1, outputs 0 otherwise. XOR GATE-Outputs O if both bits are equal, outputs 1 otherwise.
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage