Реализована печать в двоичном виде

main
GorokhovDE 4 месяцев назад
Родитель 157184394d
Сommit e3ed9e7cf6

@ -58,11 +58,27 @@ void test_print_array_in_hex() {
cout << "\n"; cout << "\n";
} }
char bit_digit(uint8_t byte, uint8_t bit) {
return (byte & (1 << bit)) ? '1' : '0';
}
void print_in_binary(uint8_t byte) {
for (int8_t bit = 7; bit >= 0; --bit) {
cout << bit_digit(byte, bit);
}
}
void test_print_in_binary() {
print_in_binary(0x2a); cout << "\n"; // 00101010
}
int main() { int main() {
test_nibble_to_hex(); test_nibble_to_hex();
test_nibbles(); test_nibbles();
test_print_in_hex(); test_print_in_hex();
test_print_array_in_hex(); test_print_array_in_hex();
test_print_in_binary();
return 0; return 0;
} }

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