Commit 4e35119d authored by Michael's avatar Michael

michael.davityan:execise_05-18v2

parent 5ccbd392
......@@ -4,47 +4,48 @@
int
main()
{
std::cout << "============================================================================================================\n";
std::cout << "|------------------------------- NUMBER SYSTEMS TABLE CONTENT... --------------------------------|\n";
std::cout << "============================================================================================================\n";
std::cout << "|" << std::setw(27) << "binary system|" << std::setw(27) << "octal system|"
<< std::setw(27) << "decimal system|" << std::setw(27) << "hexadecimal system|\n";
std::cout << "============================================================================================================\n";
std::cout << "=====================================================================\n";
std::cout << "|------------ NUMBER SYSTEMS TABLE CONTENT... ------------|\n";
std::cout << "=====================================================================\n";
std::cout << "|" << std::setw(17) << "decimal|" << std::setw(17) << "binary|"
<< std::setw(17) << "octal|" << std::setw(17) << "hexadecimal|" << std::endl;
std::cout << "=====================================================================\n";
const int DECIMAL_LIMIT = 256;
for (int number = 1; number <= DECIMAL_LIMIT; ++number) {
int powerOfTwo = 256;
std::cout << "|" << std::setw(18);
do {
int variableForCalculate = number / powerOfTwo;
std::cout << variableForCalculate % 2;
powerOfTwo /= 2;
} while (powerOfTwo != 0);
std::cout << "|" << std::setw(24);
powerOfTwo = 64;
do {
int variableForCalculate = number / powerOfTwo;
std::cout << variableForCalculate % 8;
powerOfTwo /= 8;
} while (powerOfTwo != 0);
std::cout << "|" << std::setw(26)<< number << "|" << std::setw(23);
powerOfTwo = 256;
do {
int variableForCalculate = number / powerOfTwo;
int beforeNine = variableForCalculate % 16;
if (beforeNine <= 9) {
std::cout << beforeNine;
} else {
char afterNine = 'a';
afterNine = afterNine + (beforeNine - 10);
std::cout << afterNine;
}
powerOfTwo /= 16;
} while (powerOfTwo != 0);
std::cout << "|\n";
std::cout << "|" << std::setw(16) << number << "|";
const int SYSTEM_LIMIT = 16;
for (int systemType = 2; systemType <= SYSTEM_LIMIT; systemType *= 2) {
int decimalLimit = DECIMAL_LIMIT;
int powerOfSystemType = 1;
int probels = 1;
if (4 == systemType) {
continue;
}
do {
decimalLimit /= systemType;
powerOfSystemType *= systemType;
++probels;
} while (decimalLimit != 0);
std::cout << std::setw(17 - probels);
do {
const int variableForCalculate = number / powerOfSystemType;
const int bitValue = variableForCalculate % systemType;
if (bitValue < 10) {
std::cout << bitValue;
} else {
char afterNine = 'a';
afterNine = afterNine + (bitValue - 10);
std::cout << afterNine;
}
powerOfSystemType /= systemType;
} while (powerOfSystemType != 0);
std::cout << "|";
}
std::cout << std::endl;
}
std::cout << "============================================================================================================\n";
std::cout << "|----------------------------------------- end of table... --------------------------------------------|\n";
std::cout << "============================================================================================================"
<< std::endl;
std::cout << "=====================================================================\n";
std::cout << "|----------------------- end of table... -----------------------|\n";
std::cout << "====================================================================="
<< std::endl;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment