Add absolutely new main function

master
Артем Рогозин 1 год назад
Родитель f14b6e3fec
Сommit 8313e24a46

@ -1,28 +1,64 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <cassert>
#include "lab04.h"
using namespace std; using namespace std;
int main() { // Ôóíêöèÿ äëÿ ïðåäñòàâëåíèÿ nibble (4 áèò) â øåñòíàäöàòåðè÷íîé ñèñòåìå
uint8_t singleByte = 0xAB; char nibble_to_hex(uint8_t i) {
uint8_t byteArray[] = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 }; // Ìàññèâ öèôð â øåñòíàäöàòåðè÷íîé ñèñòåìå
char digits[] = "0123456789abcdef";
cout << "Print in Hex:" << endl; // Ïðîâåðêà íà êîððåêòíîñòü àðãóìåíòà
print_in_hex(singleByte); assert(0x0 <= i && i <= 0xf);
cout << endl; // Âîçâðàùàåì ñèìâîë äëÿ nibble èç ìàññèâà digits
print_in_hex(byteArray, sizeof(byteArray)); return digits[i];
}
// Ôóíêöèÿ äëÿ ïå÷àòè îäíîãî áàéòà â øåñòíàäöàòåðè÷íîé è äâîè÷íîé ôîðìå
void print_in_hex(uint8_t byte) {
// Ïå÷àòü â øåñòíàäöàòåðè÷íîé ôîðìå
cout << "Hex: " << nibble_to_hex(byte >> 4) << nibble_to_hex(byte & 0xf) << endl;
cout << "\nPrint in Binary:" << endl; // Ïå÷àòü â äâîè÷íîé ôîðìå
print_in_binary(singleByte); cout << "Binary: ";
for (int i = 7; i >= 0; --i) {
cout << ((byte >> i) & 1);
}
cout << endl; cout << endl;
print_in_binary(byteArray, sizeof(byteArray)); }
int main() {
// Òåñòèðîâàíèå ôóíêöèè nibble_to_hex
//for (int i = 0; i <= 0xf; ++i) {
//assert(nibble_to_hex(i) == nibble_to_hex(i));
//}
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');
// Ïå÷àòü áàéòà â øåñòíàäöàòåðè÷íîé è äâîè÷íîé ôîðìå
uint8_t test_byte = 0x2f;
print_in_hex(test_byte);
return 0; return 0;
} }
int main_calc() { int main_calc() {
uint16_t operand1, operand2; uint16_t operand1, operand2;
char operation; char operation;

Загрузка…
Отмена
Сохранить