4-Bit Width Logic

Problem #147

Tags: logic

Who solved this?

Previous:DEMUX Next:Half-Adder


The basic logic gates we've looked at so far have received 1-bit inputs, and transmitted 1-bit outputs. But it's often useful to be able to process "wider" signals over multiple bits. For this problem, the circuitboard will be pre-installed with: * a single 4-bit input, * a 3-bit selector input S which selects the function to be performed, * a 4-bit selector input T which selects the output pins to which the result should be routed, and * 4 possible 4-bit outputs.

The states of the S pins will determine which function is to be performed:

0: A AND B
1: A OR B
2: A XOR B
3: (unused)
4: A NAND B
5: A NOR B
6: A XNOR B
7: (unused)

We might wonder how to calculate an expression like 5 XNOR 7. First convert both numbers to binary, then perform the 1-bit functions on each bit individually.

0101 = 5
0111 = 7
----
1101 = 14

Therefore, 5 XNOR 7 = 14.

It's also worth noting that when reading binary numbers from pins, the 0th pin will hold the Most Significant Bit (MSB), which is called "Big-Endian" Notation. So reading the bits from lowest pin to highest pin is analogous to reading the binary number from left to right.

The 4 outputs to receive the result will be labeled A (the 1st letter) through D (the 4th letter). The result of the function should be routed to the letter whose position is equivalent to T + 1.

 T  | Route to Output 
----|-----------------
 00 |        A        
 01 |        B        
 10 |        C        
 11 |        D        

All other outputs should read 0000.

The circuit board will come pre-installed with INPUT and OUTPUT chips as shown below:

───────┐                                                   ┌────────
       ├─● A[0]                                     A[0] ●─┤        
       ├─● A[1]                                     A[1] ●─┤        
       ├─● A[2]                                     A[2] ●─┤        
       ├─● A[3]                                     A[3] ●─┤        
       │                                                   │        
       ├─● B[0]                                     B[0] ●─┤        
       ├─● B[1]                                     B[1] ●─┤        
 INPUT ├─● B[2]                                     B[2] ●─┤        
       ├─● B[3]                                     B[3] ●─┤        
       │                                                   │ OUTPUT 
       ├─● S[0]                                     C[0] ●─┤        
       ├─● S[1]                                     C[1] ●─┤        
       ├─● S[2]                                     C[2] ●─┤        
       │                                            C[3] ●─┤        
       ├─● T[0]                                            │        
       ├─● T[1]                                     D[0] ●─┤        
───────┘                                            D[1] ●─┤        
                                                    D[2] ●─┤        
                                                    D[3] ●─┤        
                                                           └────────

Solving this problem will allow you to place 4-bit, 8-bit, and 16-bit chips as well, as building those should be trivial if you can solve this problem. However, understand that wider chips have their inputs labeled somewhat differently. For AND, NAND, OR, NOR, XOR, AND XNOR chips more than 1 bit wide, their inputs are called A and B.

This will also unlock 4-channel MUX4 and DEMUX4 chip variants in multiple bit widths as well. A MUX4 chip will take 4 input signals A, B, C, and D, then select which to route to the output based on a 2-bit selector S. This behavior is mirrored for chips of any bitwidth, and the DEMUX4 chip works similarly in routing a single input to 4 possible outputs W, X, Y, and Z.

Problem Statement

Digital Logic Circuit Interface
For these Digital Logic Circuits tasks, you will not be providing an answer string you would for other tasks.
Instead, your Solution Code will be interpreted directly to place chips onto the circuitboard and connect them with wires.
Click here to learn the Digital Logic Circuit Syntax used on this site.

After the chips have been placed and connected, the server will run a series of tests, randomly assigning values to the input pin(s) and checking to see if the output pins read the corresponding expected values. If all tests produce the expected outputs, then the circuitboard is considered a success.

Even though we won't be using the "Your answer" box, you'll still need to put something in that box to submit your solution. Just put anything - it will not be passed to the interpreter.

You need to login to get test data and submit solution.