GATE || Digital Logic || PYQ || 2026 || Module 4: Combinational Circuit (JavaScript)
Learn GATE || Digital Logic || PYQ || 2026 || Module 4: Combinational Circuit (JavaScript) step by step with clear examples and exercises.
Title: GATE Digital Logic PYQ 2026 - Module 4: Combinational Circuit (JavaScript)
Why This Matters
In this comprehensive lesson, we delve into the intricacies of Combinational Circuits as per the GATE 2026 syllabus. Understanding combinational circuits is crucial for digital logic design, which is a fundamental aspect of computer engineering and vital for cracking competitive exams like GATE. This knowledge will also help you identify and debug real-world programming issues related to digital logic.
Prerequisites
Before diving into the core concept, it's essential to have a solid understanding of:
- JavaScript basics
- Familiarity with Boolean algebra
- In-depth knowledge of Logic gates (AND, OR, NOT, XOR, NAND, NOR)
- Understanding of truth tables and their role in digital logic design
- Basic understanding of bitwise operations
- Knowledge of JavaScript functions and control structures
Core Concept
Combinational circuits are digital circuits that produce an output solely based on the current input values. There is no memory involved in combinational circuits; once the input changes, the output changes immediately. Combinational circuits can be built using logic gates and their combinations.
A truth table represents the relationship between inputs and outputs for a given combinational circuit. For example, consider a 2-input OR gate:
| Input A | Input B | Output |
|---------|--------|--------|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
In JavaScript, we can represent the OR gate using a function:
function orGate(inputA, inputB) {
return (inputA || inputB);
}
Here's how it works: The || operator performs a logical OR operation. If either inputA or inputB is true (1), the output will be true (1). Otherwise, the output will be false (0).
Truth Table Generation in JavaScript
To generate truth tables for more complex combinational circuits, we can create a function that takes an array of inputs and their respective weights (1 or 0) as arguments. Then, we can use bitwise operations to calculate the output:
function generateTruthTable(inputs, output) {
const truthTable = [];
for (let i = 0; i < Math.pow(2, inputs.length); i++) {
let binaryRepresentation = i.toString(2).padStart(inputs.length, '0');
let inputValues = binaryRepresentation.split('').map(num => parseInt(num));
let outputValue = inputValues[output] ? 1 : 0;
truthTable.push({ inputs: inputValues, output: outputValue });
}
return truthTable;
}
Truth Table-Based Implementation of Combinational Circuits in JavaScript
Using the generated truth table, we can create a function that implements a combinational circuit based on its truth table. Here's an example for a 2-input AND gate:
function andGate(inputA, inputB) {
const truthTable = generateTruthTable([inputA, inputB], 0);
let outputValue;
truthTable.forEach((row) => {
if (row.inputs[0] === 1 && row.inputs[1] === 1) {
outputValue = 1;
} else {
outputValue = 0;
}
});
return outputValue;
}
Worked Example
Let's create a JavaScript program to implement a 3-input XOR gate using the truth table and write tests for it.
function generateTruthTable(inputs, output) {
const truthTable = [];
for (let i = 0; i < Math.pow(2, inputs.length); i++) {
let binaryRepresentation = i.toString(2).padStart(inputs.length, '0');
let inputValues = binaryRepresentation.split('').map(num => parseInt(num));
let outputValue = inputValues[output] ? 1 : 0;
truthTable.push({ inputs: inputValues, output: outputValue });
}
return truthTable;
}
function xorGate(inputA, inputB, inputC) {
const truthTable = generateTruthTable([inputA, inputB, inputC], 0);
let outputValue;
truthTable.forEach((row) => {
if (
(row.inputs[0] === 1 && row.inputs[1] === 0 && row.inputs[2] === 0) ||
(row.inputs[0] === 0 && row.inputs[1] === 1 && row.inputs[2] === 0) ||
(row.inputs[0] === 0 && row.inputs[1] === 0 && row.inputs[2] === 1) ||
(row.inputs[0] === 1 && row.inputs[1] === 1 && row.inputs[2] === 0) ||
(row.inputs[0] === 1 && row.inputs[1] === 0 && row.inputs[2] === 1) ||
(row.inputs[0] === 0 && row.inputs[1] === 1 && row.inputs[2] === 1)
) {
outputValue = 1;
} else {
outputValue = 0;
}
});
return outputValue;
}
// Test cases for the XOR gate function
console.log(xorGate(0, 0, 0)); // Output: 0
console.log(xorGate(0, 0, 1)); // Output: 1
console.log(xorGate(0, 1, 0)); // Output: 1
console.log(xorGate(0, 1, 1)); // Output: 0
console.log(xorGate(1, 0, 0)); // Output: 1
console.log(xorGate(1, 0, 1)); // Output: 0
console.log(xorGate(1, 1, 0)); // Output: 0
console.log(xorGate(1, 1, 1)); // Output: 0
Common Mistakes
- ### Forgetting to handle all possible input combinations for each gate type
Ensure that your combinational circuit function handles all possible input combinations as per the truth table for each gate type.
- ### Using incorrect operators for logic gates
Make sure you use the correct JavaScript operator (&&, ||, !) for each gate type in your implementation.
- ### Neglecting to optimize complex combinational circuits
Optimization is crucial when dealing with complex combinational circuits to reduce the number of gates and improve efficiency.
Subheadings under Common Mistakes:
- Forgetting to handle all possible input combinations for each gate type
- Using incorrect operators for specific logic gates
- Neglecting to optimize complex combinational circuits
Practice Questions
- Implement a 2-input AND gate using JavaScript. Write tests to verify its functionality.
- Create a JavaScript program that implements a 3-input NAND gate using truth tables and write test cases for it.
- Optimize the XOR gate implementation from the worked example to reduce the number of gates used.
- Implement a 4-bit full adder in JavaScript using combinational circuits. Write tests to verify its functionality.
- Design and implement a 2-input multiplexer (MUX) in JavaScript using truth tables, and write test cases for it.
- Design and implement a 4-to-1 multiplexer (4:1 MUX) in JavaScript using combinational circuits, and write test cases to verify its functionality.
- Implement a 2-input half adder in JavaScript using combinational circuits, and write tests to verify its functionality.
- Implement a 3-input half adder in JavaScript using combinational circuits, and write tests to verify its functionality.
- Design and implement a 4-bit binary counter in JavaScript using combinational circuits, and write test cases to verify its functionality.
- Design and implement a 4-bit binary up-down counter (BCD) in JavaScript using combinational circuits, and write test cases to verify its functionality.
FAQ
### How can I implement more complex combinational circuits in JavaScript?
You can create more complex combinational circuits by combining simple gates like AND, OR, NOT, XOR, NAND, and NOR using their truth tables and JavaScript functions.
### What are some real-world applications of combinational circuits?
Combinational circuits are used in various digital systems such as arithmetic logic units (ALUs), microprocessors, memory address decoders, and encryption/decryption devices.
### How can I optimize complex combinational circuits in JavaScript?
Optimization techniques for complex combinational circuits include Karnaugh maps, Quine-McCluskey algorithm, and logic minimization software tools.
Subheadings under FAQ:
- Implementing more complex combinational circuits in JavaScript
- Real-world applications of combinational circuits
- Optimizing complex combinational circuits in JavaScript