GF2::Matrix — Logical Shift Operators
Methods to perform binary left and right shifts for the rows in a bit-matrix where zeros are shifted in as needed.
constexpr Matrix &operator<<=(std::size_t p); (1)
constexpr Matrix &operator>>=(std::size_t p); (2)
constexpr Matrix operator<<(std::size_t p) const; (3)
constexpr Matrix operator>>(std::size_t p) const; (4)
| 1 | Left-shift the rows in this bit-matrix p places (zeros are shifted in). |
| 2 | Right-shift the rows in this bit-matrix p places (zeros are shifted in). |
| 3 | Returns a bit-matrix that is this one with its rows left shifted by p places |
| 4 | Returns a bit-matrix that is this one with its rows right shifted by p places |
The first two methods are destructive (i.e. operate in-place) and return a reference to *this so can be chained with other calls.
Example
#include <GF2/GF2.h>
int main()
{
auto m = GF2::Matrix<>::ones(4);
std::cout << "Left shift (rows printed here in bit-order!):\n"; (1)
std::cout << "m: \n" << m.to_bit_order() << '\n';
std::cout << "m << 1: \n" << (m << 1).to_bit_order() << '\n';
std::cout << "m << 3: \n" << (m << 3).to_bit_order() << '\n';
std::cout << "m << 5: \n" << (m << 5).to_bit_order() << '\n';
std::cout << std::endl;
std::cout << "Right shift (rows printed here in bit-order!):\n";
std::cout << "m: \n" << m.to_bit_order() << '\n';
std::cout << "m >> 1: \n" << (m >> 1).to_bit_order() << '\n';
std::cout << "m >> 3: \n" << (m >> 3).to_bit_order() << '\n';
std::cout << "m >> 5: \n" << (m >> 4).to_bit_order() << '\n';
std::cout << std::endl;
}
| 1 | It is more intuitive to see the effect of left & right shifts if the rows are printed in bit-order where the the least significant bit is on the right. |
Output
m:
1111
1111
1111
1111
m >> 1:
0111
0111
0111
0111
m >> 3:
0001
0001
0001
0001
m >> 5:
0000
0000
0000
0000