Click here to Skip to main content
13,446,115 members (38,656 online)
Rate this:
Please Sign up or sign in to 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 }
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 5-Feb-13 2:06am
Fredrik Bornander 5-Feb-13 8:15am
Is this homework?
Maxbummer 5-Feb-13 8:17am
It's a project

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.



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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180314.2 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100