summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp')
-rw-r--r--Bachelor/Prog1/Prakt2/prg1p2_6/prg1p2_6.cpp59
1 files changed, 59 insertions, 0 deletions
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 <iostream>
+#include <iomanip>
+#include <cmath>
+
+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 <int> (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 <int> (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