stuff-from-scratch/test/core/TestByteUtils.cpp

45 lines
1.3 KiB
C++
Raw Normal View History

2024-01-02 16:14:23 +00:00
#include "Bits.h"
2022-11-29 18:00:19 +00:00
#include "TestFramework.h"
#include <iostream>
2024-01-02 16:14:23 +00:00
TEST_CASE(TestReadBits, "core")
{
2024-01-02 16:14:23 +00:00
auto byte = Bits::getFromString("00110101");
2022-11-30 18:28:50 +00:00
//std::cout << "Value is " << static_cast<unsigned>(byte) << std::endl;
2024-01-02 16:14:23 +00:00
auto string_rep = Bits::toString(byte);
2022-11-30 18:28:50 +00:00
//std::cout << "String rep is " << string_rep << std::endl;
2024-01-02 16:14:23 +00:00
auto slice = Bits::getMBitsAtN(byte, 3, 3);
//std::cout << "Slice is " << Bits::toString(slice) << std::endl;
2023-01-23 11:06:30 +00:00
(void) slice;
2022-11-23 17:51:36 +00:00
uint32_t input {12345678};
2024-01-02 16:14:23 +00:00
auto byte0 = Bits::getByteN(input, 0);
auto byte1 = Bits::getByteN(input, 1);
auto byte2 = Bits::getByteN(input, 2);
auto byte3 = Bits::getByteN(input, 3);
2022-11-23 17:51:36 +00:00
2023-01-23 11:06:30 +00:00
(void)byte0;
(void)byte1;
(void)byte2;
(void)byte3;
2024-01-02 16:14:23 +00:00
//std::cout << "Byte0 is " << Bits::toString(byte0) << std::endl;
//std::cout << "Byte1 is " << Bits::toString(byte1) << std::endl;
//std::cout << "Byte2 is " << Bits::toString(byte2) << std::endl;
//std::cout << "Byte3 is " << Bits::toString(byte3) << std::endl;
2022-11-30 18:28:50 +00:00
//std::cout << "Mirroring" << std::endl;
2022-11-28 10:16:04 +00:00
2024-01-02 16:14:23 +00:00
//auto out = Bits::mirror(byte);
//std::cout << "Mirror is " << Bits::toString(out) << std::endl;
2022-11-28 10:16:04 +00:00
2022-11-28 18:05:39 +00:00
unsigned hold = byte;
hold = (hold << 5) + 3;
2023-01-23 11:06:30 +00:00
(void)hold;
2024-01-02 16:14:23 +00:00
//std::cout << "Big val is " << Bits::toString(hold, 16) << std::endl;
}