From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp (limited to 'Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp') diff --git a/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp new file mode 100644 index 0000000..70abc04 --- /dev/null +++ b/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp @@ -0,0 +1,59 @@ +// Programmieren 1, Praktikum 2, Aufgabe 6 +// Sven Eisenhauer +// 06.11.2004 +// +// file: prg1p2_6.cpp +// +// purpose: generate a table of bin, oct and hex presentation of the numbers from 1 to 256 +// +// + +#include +#include +#include + +using std::cin; +using std::cout; +using std::endl; +using std::setw; +using std::hex; +using std::dec; + +const int iBit=8; // 256 is 8 bit + +int iDec,iOct,iHex,iBin,iTemp; + +int main() +{ + cout << setw(5) << "Dec" << setw (11) << "Binary" << setw(7) << "Octal" << setw(5) << "Hex" << endl; + + for (int iCounter=1;iCounter<=256;iCounter++) + { + iDec=iCounter; + iTemp=0; + iBin=0; + iOct=0; + // generate binary + for (int iBinC=iBit;iBinC>=0;iBinC--) + { + iTemp = iDec % 2; + iDec = iDec / 2; + iBin += iTemp * static_cast (pow(10,iBit-iBinC)); + + } + // generate octal + iDec=iCounter; + for ( int iOctC=3;iOctC>=0;iOctC--) + { + iTemp = iDec % 8; + iDec = iDec / 8; + iOct += iTemp * static_cast (pow(10,3-iOctC)); + } + cout << setw(5) << dec << iCounter << setw (11) << iBin << setw(7) << iOct << setw(5) << hex << iCounter << endl; + if (!(iCounter%23)) + cout << endl << setw(5) << "Dec" << setw (11) << "Binary" << setw(7) << "Octal" << setw(5) << "Hex" << endl; + } + + + return 0; +}// end main -- cgit v1.2.3