0% found this document useful (0 votes)
2 views6 pages

Exp 4

The document outlines the implementation of 4x1 and 8x1 multiplexers using C++. It includes the theory behind multiplexers, their truth tables, and provides C++ code for both types of multiplexers, detailing user input for data and selection lines. The code validates inputs and displays the corresponding output based on the selected input line.

Uploaded by

Sujeet Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Exp 4

The document outlines the implementation of 4x1 and 8x1 multiplexers using C++. It includes the theory behind multiplexers, their truth tables, and provides C++ code for both types of multiplexers, detailing user input for data and selection lines. The code validates inputs and displays the corresponding output based on the selected input line.

Uploaded by

Sujeet Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment -4

Aim: Implementing 4x1 and 8x1 Multiplexers


Theory:

A multiplexer is a combinational circuit that has 2n input lines and a single output line.
The multiplexer is a multi-input and single-output combinational circuit. The binary
information is received from the input lines and directed to the output line. On the basis
of the values of the selection lines, one of these data inputs will be connected to the
output..

1. Implementing a 4×1 Multiplexer in C++


In the 4×1 multiplexer, there is a total of four inputs, i.e., A0, A1, A2, and A3, 2 selection
lines, i.e., S0 and S1 and single output, i.e., Y. On the basis of the combination of inputs
that are present at the selection lines S0 and S1, one of these 4 inputs are connected to
the output. The block diagram and the truth table of the 4×1 multiplexer are given below.
Truth Table for 4×1 MUX

C++ Code:

#include <iostream>
using namespace std;

// 4x1 Multiplexer function


int mux4x1(int S1, int S0, int D0, int D1, int D2, int D3) {
switch ((S1 << 1) | S0) {
case 0: return D0;
case 1: return D1;
case 2: return D2;
case 3: return D3;
default: return -1; // Should never happen
}
}
int main() {
int D0, D1, D2, D3, S0, S1;
// Taking user input
cout << "Enter data inputs (D0 D1 D2 D3): ";
cin >> D0 >> D1 >> D2 >> D3;
cout << "Enter select lines (S1 S0): ";
cin >> S1 >> S0;

// Validating select lines


if (S0 < 0 || S0 > 1 || S1 < 0 || S1 > 1) {
cout << "Invalid select inputs! Use only 0 or 1.\n";
return 1;
}

// Calling the MUX function


int output = mux4x1(S1, S0, D0, D1, D2, D3);

// Displaying the output


cout << "Output (Y): " << output << endl;

return 0;
}

2. Implementing an 8×1 Multiplexer in C++


In the 8 to 1 multiplexer, there are total eight inputs, i.e., A0, A1, A2, A3, A4, A5, A6, and A7,
3 selection lines, i.e., S0, S1and S2 and single output, i.e., Y. On the basis of the
combination of inputs that are present at the selection lines S0, S1, and S2, one of these 8
inputs are connected to the output. The block diagram and the truth table of the 8×1
multiplexer are given below.
Truth Table:

#include <iostream>

using namespace std;

// Function to implement 8×1 Multiplexer

int mux8to1(int s2, int s1, int s0, int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7) {

int select = (s2 << 2) | (s1 << 1) | s0; // Convert selector bits to decimal

switch (select) {

case 0: return d0;

case 1: return d1;

case 2: return d2;

case 3: return d3;

case 4: return d4;

case 5: return d5;

case 6: return d6;


case 7: return d7;

default: return -1; // Error case (should not happen)

int main() {

int s2, s1, s0; // Selector inputs

int d0 = 10, d1 = 20, d2 = 30, d3 = 40, d4 = 50, d5 = 60, d6 = 70, d7 = 80; // Data inputs

// Take selector inputs from user

cout << "Enter selector bits (s2 s1 s0): ";

cin >> s2 >> s1 >> s0;

// Validate selector inputs

if ((s2 < 0 || s2 > 1) || (s1 < 0 || s1 > 1) || (s0 < 0 || s0 > 1)) {

cout << "Invalid selector inputs! Enter only 0 or 1." << endl;

return 1;

// Get MUX output

int output = mux8to1(s2, s1, s0, d0, d1, d2, d3, d4, d5, d6, d7);

// Display output

cout << "MUX Output: " << output << endl;

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy