#include "ByteUtils.h" bool ByteUtils::MostSignificantBitIsOne(char c) { return c & (1 << 7); } ByteUtils::Word ByteUtils::GetWordFirstBit(const Word word) { return word & ByteUtils::WORD_FIRST_BIT; }; ByteUtils::Word ByteUtils::GetWordLastByte(const Word word) { return word & ByteUtils::WORD_LAST_BYTE; } unsigned char ByteUtils::getHigherNBits(unsigned char input, unsigned num) { return input >> (8 - num); } unsigned char ByteUtils::getByteN(uint32_t input, unsigned n) { return (input << 8*n) >> 24; } uint32_t ByteUtils::mirror(uint32_t byte, unsigned length) { uint32_t ret{0}; for(unsigned idx=0; idx> n; } unsigned char ByteUtils::getMBitsAtN(unsigned char input, unsigned m, unsigned n) { switch (m) { case 1: return (input & (0x01 << n)) >> n; case 2: return (input & (0x03 << n)) >> n; case 3: return (input & (0x07 << n)) >> n; case 4: return (input & (0x0F << n)) >> n; case 5: return (input & (0x1F << n)) >> n; case 6: return (input & (0x3F << n)) >> n; case 7: return (input & (0x7F << n)) >> n; case 8: return input; default: return 0; } } bool ByteUtils::getBitN(uint32_t input, unsigned n) { return input & (1 << n); } unsigned char ByteUtils::getFromString(const std::string& string) { unsigned char ret{0}; if (string.length() < 8) { return ret; } for(unsigned idx=0; idx<8; idx++) { if (string[idx] == '1') { ret |= (0x01 << (7 - idx)); } } return ret; } std::string ByteUtils::toString(uint32_t input, unsigned length) { std::string ret; if (length > 8) { unsigned overshoot = length - 8; for(unsigned idx=0; idx(buffer, reverse); } ByteUtils::DWord ByteUtils::ToDWord(char* buffer, bool reverse) { return ToType(buffer, reverse); } ByteUtils::QWord ByteUtils::ToQWord(char* buffer, bool reverse) { return ToType(buffer, reverse); } bool ByteUtils::Compare(char* buffer, const char* tag, unsigned size) { for(unsigned idx=0; idx