Commit 0e2933e9 authored by Michael's avatar Michael

michael.davityan:exercise_05_18v3

parent 4e35119d
#include <iostream>
#include <iomanip>
#include <cmath>
int
main()
......@@ -15,29 +16,27 @@ main()
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);
int denuminator = SYSTEM_LIMIT / systemType;
if (16 == systemType) {
++denuminator;
}
int powerOfSystemType = pow(systemType, denuminator + 1);
int probels = denuminator + 2;
std::cout << std::setw(17 - probels);
do {
const int variableForCalculate = number / powerOfSystemType;
const int bitValue = variableForCalculate % systemType;
powerOfSystemType /= systemType;
if (bitValue < 10) {
std::cout << bitValue;
} else {
char afterNine = 'a';
afterNine = afterNine + (bitValue - 10);
std::cout << afterNine;
continue;
}
powerOfSystemType /= systemType;
char afterNine = 'a';
afterNine = afterNine + (bitValue - 10);
std::cout << afterNine;
} while (powerOfSystemType != 0);
std::cout << "|";
}
......
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