Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I was proposed a project that sounds like this.

Consider a set of logical gates like AND, OR, XOR or NOT. Allow for building any logical circuit by connecting such gates.
Provide input (0/1) to a number of gates and collect the results at the output of some of the gates.
Be able to read the description of the circuit from a file.

Additional information that I was given: I have to build some classes/interfaces allowing to model such circuits.After that, you have to simulate the flow of the input signals to the end nodes and eventually to collect the results on some output connectors.It is not about writing a program to evaluate logical propositions like p&q|r&!p or to write truth tables. Rather you have some signals flowing through connectors and processed at the level of each logical gate.

I was suggested an idea like the one below, for a single AND gate, 2 inputs and a single output. Is this a good approach?

01 public class LogicAnd extends Gate
02 {
03 public LogicAnd(int a, int b, int q) {
04 a_ = a; b_ =b; q_ = q;
05 }
06
07 public void Evaluate(int[] signals) {
08 signals[q_] = signals[a_]&signals[b_];
09 }
10 }

Has anyone done anything of this kind? What would you do, how would you start/shape this problem? I am looking for any help as much as possible, open to hints and solutions, anything is helpful.
Posted
Comments
Fredrik Bornander 5-Feb-13 8:15am    
Is this homework?
Maxbummer 5-Feb-13 8:17am    
It's a project

1 solution

When I was at uni back in the late 1980's we had an introductory course where we were taught Scheme (a LISP dialect). The book that was used throughout the course was Structure and Interpretation of Computer Programs[^] by H. Abelson and G.J. Sussman.
One of the things that was engraved indelibly in my mind was an expression simulator written completely in Scheme. One of the principles that was used to solve this was called Propagation of Constraints[^] in Chapter 3 about Modularity, Objects, and State[^].
Please read this! Even though you'll not be implementing this in Scheme, there's still a lot to be learned from that book, especially how signals\states propagate through the network. The Celsius-Fahrenheit calculator works both ways for instance without you having to rewrite anything. It merely depends which pin is assigned a value the correct counterpart will be calculated. Back then I was really amazed at this principle.

[Edit]This chapter is a bit closer to what you are looking for while I still think that above mentioned principle will be helpful in more general expression evaluators: 3.3.4 A Simulator for Digital Circuits[^][/Edit]

If you have any doubts, leave me a comment.

Cheers,

—Manfred
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900