|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#include
|
|
|
|
|
#include
|
|
|
|
|
#include
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <locale>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
char nibble_to_hex(uint8_t i) {
|
|
|
|
@ -54,3 +55,44 @@ print_in_binary(bytes[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void run_tests() {
|
|
|
|
|
assert(nibble_to_hex(0x0) == '0');
|
|
|
|
|
assert(nibble_to_hex(0x1) == '1');
|
|
|
|
|
assert(nibble_to_hex(0x2) == '2');
|
|
|
|
|
assert(nibble_to_hex(0x3) == '3');
|
|
|
|
|
assert(nibble_to_hex(0x4) == '4');
|
|
|
|
|
assert(nibble_to_hex(0x5) == '5');
|
|
|
|
|
assert(nibble_to_hex(0x6) == '6');
|
|
|
|
|
assert(nibble_to_hex(0x7) == '7');
|
|
|
|
|
assert(nibble_to_hex(0x8) == '8');
|
|
|
|
|
assert(nibble_to_hex(0x9) == '9');
|
|
|
|
|
assert(nibble_to_hex(0xa) == 'a');
|
|
|
|
|
assert(nibble_to_hex(0xb) == 'b');
|
|
|
|
|
assert(nibble_to_hex(0xc) == 'c');
|
|
|
|
|
assert(nibble_to_hex(0xd) == 'd');
|
|
|
|
|
assert(nibble_to_hex(0xe) == 'e');
|
|
|
|
|
assert(nibble_to_hex(0xf) == 'f');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
setlocale(LC_ALL, "Russian");
|
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
|
|
cout << "Введите целое число:\n";
|
|
|
|
|
cin >> i;
|
|
|
|
|
if (cin.fail()) {
|
|
|
|
|
cerr << "Ошибка: некорректный ввод. Пожалуйста, введите целое число.\n";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t test = i;
|
|
|
|
|
|
|
|
|
|
cout << "Шестнадцатеричный вывод:\n";
|
|
|
|
|
print_in_hex(&test, sizeof(test));
|
|
|
|
|
cout << "\nДвоичный вывод:\n";
|
|
|
|
|
print_in_binary(&test, sizeof(test));
|
|
|
|
|
cout << '\n';
|
|
|
|
|
return 0;
|
|
|
|
|
}
|