| | |
Need Help In Decoder Programming
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2007
Posts: 5
Reputation:
Solved Threads: 0
Hi, i'm new to this website. I have recently came across a qns given by a friend and i'm thinking how to do it. Hope u all can help me...
Here is the qns:
The circuit below shows a decoder circuit using 3-to-8 Decoder and 2-to-4 Decoder with logic gates.
*The Pic is in the attachment file.
Your task is to simulate the output logic level (ie: “0” or “1”) of each device in the above circuit. You will need to derive the following classes :
i) 3-to-8 Decoder
ii) 2-to-4 Decoder
iii) AND gate
Thank you for viewing and your help...
Here is the qns:
The circuit below shows a decoder circuit using 3-to-8 Decoder and 2-to-4 Decoder with logic gates.
*The Pic is in the attachment file.
Your task is to simulate the output logic level (ie: “0” or “1”) of each device in the above circuit. You will need to derive the following classes :
i) 3-to-8 Decoder
ii) 2-to-4 Decoder
iii) AND gate
Thank you for viewing and your help...
Well, a bitwise AND operation is performed using the '&' operator between two numbers
eg, 'n' will be 4
You'll need to know about Bitwise operations - (Binary arithmetic)
http://en.wikipedia.org/wiki/Bitwise_operation
In C++, the <bitset> library may come in useful.
have a look here for a 2-to-4 decoder
http://en.wikipedia.org/wiki/Image:Decoder_Example.svg
eg,
CPP Syntax (Toggle Plain Text)
int n = 6 & 12; // 0000 0110 // & // 0000 1100
You'll need to know about Bitwise operations - (Binary arithmetic)
http://en.wikipedia.org/wiki/Bitwise_operation
In C++, the <bitset> library may come in useful.
have a look here for a 2-to-4 decoder
http://en.wikipedia.org/wiki/Image:Decoder_Example.svg
Last edited by Bench; Jan 10th, 2007 at 12:26 am. Reason: Had to disable smileys
¿umop apisdn upside down? •
•
Join Date: Sep 2006
Posts: 327
Reputation:
Solved Threads: 22
For a 2 input AND gate, you have 4 possible combination of inputs(0 to 3 in binary) . The output will only be a 1 if the two inputs are a 1, otherwise the output is a 0.
For a 2-4 bit decoder, you have an output for each combination of input. eg, If a=0 and b = 0 then D0= 0, or if a=0 and b=1 then D1=1 etc., just google the Truth Table for each chip. The 3-8 is the same with 3 inputs and 8 possible outputs...
For a 2-4 bit decoder, you have an output for each combination of input. eg, If a=0 and b = 0 then D0= 0, or if a=0 and b=1 then D1=1 etc., just google the Truth Table for each chip. The 3-8 is the same with 3 inputs and 8 possible outputs...
Last edited by Colin Mac; Jan 10th, 2007 at 10:32 am.
•
•
Join Date: Jan 2007
Posts: 5
Reputation:
Solved Threads: 0
This is a small program i have try to do but with errors... can anyone help me to solve up the error?
Thanks for helping in advance...
c Syntax (Toggle Plain Text)
//Miniproject #include <iostream> using namespace std; class decoder { protected: int decoderType; public: void setdecoderType(int); void showdecoder(void); }; void decoder:: setdecoderType(int c) { decoderType = c; } void decoder::showdecoder() { switch (decoderType) { case '000': cout << "0" << endl; break; case '001': cout << "1" << endl; break; case '010': cout << "2" << endl; break; case '011': cout << "3" << endl; break; case '100': cout << "4" << endl; break; case '101': cout << "5" << endl; break; case '110': cout << "6" << endl; break; case '111': cout << "7" << endl; break; default: cout << "Wrong entry! Pls re-enter the 3 binary code!" << endl; break; } } void main() { Decode code; int choice=0; cout << "This is a 3 to 8 decoder. "; cout << "Please enter the 3 binary code!(E.g. 001) "; cin >> choice; code.setdecodertype(choice); cout << "After decoding… The number is\n "; code.showdecoder(); }
Last edited by WaltP; Jan 16th, 2007 at 4:24 am. Reason: Code Tags! When you enter your question, thos are instructions, not smudges, in the input box. Please read... And format your code so it can be read.
First of all:
use int main() instead of void main()
please use code tags, it makes your code easier to read as does indention
With that said:
you have a few typo's in your code:
Your class is called ' decoder ' not ' Decode', the line above to 'decoder code'
There is no function 'setdecodertype'. Change this to 'setdecoderType'.
Please keep in mind that C++ is casesensitive and therefore: a!=A
Regards Niek
use int main() instead of void main()
please use code tags, it makes your code easier to read as does indention
With that said:
you have a few typo's in your code:
C++ Syntax (Toggle Plain Text)
void main() { Decode code;
C++ Syntax (Toggle Plain Text)
code.setdecodertype(choice);
Please keep in mind that C++ is casesensitive and therefore: a!=A
Regards Niek
Last edited by niek_e; Jan 16th, 2007 at 4:05 am.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
One of your coding mistake is as what niek e stated. But there is also another mistake. Your coding is prompting the user for integer but in your switch case it is comparing integer with character. You should eliminate the single quote since it represent character. Then I think your coding should be working after you correct all the small mistakes. Hope it helps.
•
•
Join Date: Jan 2007
Posts: 5
Reputation:
Solved Threads: 0
Thanks for your help for the previous errors...
Now i have rewrite the program but i still got some error and editing which need yours help.
Here is the code
First problem - For the 3 to 8 decoder, when 011 and 001 was keyed, it shows error instead of 3 and 1.
Second problem - how can i edit the program so the users can choose to use either one of the 3 decoder? I have try alot of times but all got errors.
Third problem - How can i do loop back if i key in a wrong value and i want to key in the value again after the error line has been shown?
Thanks...
Now i have rewrite the program but i still got some error and editing which need yours help.
Here is the code
//Miniproject #include <iostream> usingnamespace std; class decoder { protected: int decoderType; public: void setdecoderType(int); void showdecoder(void); }; void decoder:: setdecoderType(int c) { decoderType = c; } void decoder::showdecoder() { switch (decoderType) { case 000: cout << "0" << endl; break; case 001: cout << "1" << endl; break; case 010: cout << "2" << endl; break; case 011: cout << "3" << endl; break; case 100: cout << "4" << endl; break; case 101: cout << "5" << endl; break; case 110: cout << "6" << endl; break; case 111: cout << "7" << endl; break; default: cout << "\nWrong entry! Pls re-enter the 3 binary code!" << endl; break; } } class twofour { protected: int twofourType; public: void settwofourType(int); void showtwofour(void); }; void twofour:: settwofourType(int c) { twofourType = c; } void twofour::showtwofour() { switch (twofourType) { case 00: cout << "0" << endl; break; case 01: cout << "1" << endl; break; case 10: cout << "2" << endl; break; case 11: cout << "3" << endl; break; default: cout << "\nWrong entry! Pls re-enter the 2 binary code!" << endl; break; } } class and { protected: int andType; public: void setandType(int); void showand(void); }; void and:: setandType(int c) { andType = c; } void and::showand() { switch (andType) { case 00: cout << "0" << endl; break; case 01: cout << "0" << endl; break; case 10: cout << "0" << endl; break; case 11: cout << "1" << endl; break; default: cout << "\nWrong entry! Pls re-enter the 2 binary code!" << endl; break; } } void main() { decoder code; twofour two; and gate; int choice=0; cout << "This is a 3 to 8 decoder.\n"; cout << "Please enter the 3 binary code!(E.g. 001 to 111) "; cin >> choice; code.setdecoderType(choice); cout << "After decoding, the number is: "; code.showdecoder(); cout << "\nThis is a 2 to 4 decoder.\n"; cout << "Please enter the 2 binary code!(E.g. 00,01,10,11) "; cin >> choice; two.settwofourType(choice); cout << "After decoding, the number is: "; two.showtwofour(); cout << "\nThis is a And Gate.\n"; cout << "Please enter the 2 binary combination!(E.g. 00,01,10,11) "; cin >> choice; gate.setandType(choice); cout << "The result is: "; gate.showand(); }
First problem - For the 3 to 8 decoder, when 011 and 001 was keyed, it shows error instead of 3 and 1.
Second problem - how can i edit the program so the users can choose to use either one of the 3 decoder? I have try alot of times but all got errors.
Third problem - How can i do loop back if i key in a wrong value and i want to key in the value again after the error line has been shown?
Thanks...
C++ Syntax (Toggle Plain Text)
usingnamespace std;
•
•
•
•
First problem - For the 3 to 8 decoder, when 011 and 001 was keyed, it shows error instead of 3 and 1.
Or if you want to do it the ugly way: replace 011 with 11 and 010 with 10 in your switchcase.
•
•
•
•
Second problem - how can i edit the program so the users can choose to use either one of the 3 decoder? I have try alot of times but all got errors.
•
•
•
•
Third problem - How can i do loop back if i key in a wrong value and i want to key in the value again after the error line has been shown?
Regards Niek
•
•
•
•
That's a problem with int's. 011 == 11 and is an invalid input. 010 will probably have the same problem. Try making the input to string and switch on that.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Other Threads in the C++ Forum
- Previous Thread: AnsiString to string conversion
- Next Thread: Creating with C
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






