Add GetBit() method to Block

This commit is contained in:
Leonetienne
2022-05-24 23:18:39 +02:00
parent db0add6e6e
commit e552e1a6f8
3 changed files with 29 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
#include "GCrypt/Block.h"
#include <iostream>
#include "GCrypt/Config.h"
#include <sstream>
#include <bitset>
@@ -447,6 +448,16 @@ namespace Leonetienne::GCrypt {
return *this;
}
bool Block::GetBit(const std::size_t index) const {
// Fetch index of integer the bit is located in
const std::size_t intIndex = index / CHUNK_SIZE_BITS;
// Fetch bit index relative to that int
const std::size_t relBitIndex = index - (intIndex * CHUNK_SIZE_BITS);
return data[intIndex] & (1 << (CHUNK_SIZE_BITS - relBitIndex - 1));
}
std::uint32_t& Block::Get(const std::uint8_t row, const std::uint8_t column){
return data[MAT_INDEX(row, column)];
}