Files
MP-SPDZ/Math/BitVec.h
Marcel Keller cc0711c224 MP-SPDZ.
2018-10-11 17:20:26 +11:00

40 lines
972 B
C++

/*
* BitVec.h
*
*/
#ifndef MATH_BITVEC_H_
#define MATH_BITVEC_H_
#include "Integer.h"
class BitVec : public IntBase
{
public:
static const int n_bits = sizeof(a) * 8;
BitVec() {}
BitVec(long a) : IntBase(a) {}
BitVec(const IntBase& a) : IntBase(a) {}
BitVec operator+(const BitVec& other) const { return a ^ other.a; }
BitVec operator-(const BitVec& other) const { return a ^ other.a; }
BitVec operator*(const BitVec& other) const { return a & other.a; }
BitVec& operator+=(const BitVec& other) { *this ^= other; return *this; }
BitVec extend_bit() const { return -(a & 1); }
void pack(octetStream& os, int n = n_bits) const { os.store_int(a, DIV_CEIL(n, 8)); }
void unpack(octetStream& os, int n = n_bits) { a = os.get_int(DIV_CEIL(n, 8)); }
static BitVec unpack_new(octetStream& os, int n = n_bits)
{
BitVec res;
res.unpack(os, n);
return res;
}
};
#endif /* MATH_BITVEC_H_ */