:

Feature request - shifts

Added by: ~Lukasz Lew, 2009 VI 29

Added by: ~Lukasz Lew, 2009 VI 29

I need a library to perform large bitwise operations: AND OR NOT and SHIFT.
Are there any plans to implement them?
If not, then can you tell me where can I look?

Added by: tomek, 2009 VII 01

SHIFT's and bitwise AND (OR) are implemented in UInt<> type, sample:

#include <iostream>
#include <ttmath/ttmath.h>

int main()
{
ttmath::UInt<3> test;
test = 12345;

test.Rcl(10, 0);
// shifting to left 10 times
std::cout << test << std::endl;

test.Rcr(5, 1);
// shifting to right 5 times
// higher 5 bits will be held 1
std::cout << test << std::endl;
}

The method UInt::BitOr(...) does bitwise OR, and UInt::BitAnd(...) does bitwise AND

ttmath::UInt<3> a, b;

a = 1;
b = 2;

a.BitOr(b);
std::cout << a << std::endl; // result: 3