binary.h
Go to the documentation of this file.
#ifndef BINARY_H
#define BINARY_H
#include <itpp/base/itassert.h>
#include <itpp/itexports.h>
namespace itpp
{
class bin
{
public:
bin(): b(0) {}
bin(const int &value): b(static_cast<char>(value)) {
it_assert_debug((value == 0) || (value == 1),
"bin::bin(): value must be 0 or 1");
}
bin(const bin &inbin): b(inbin.b) {}
void operator=(const int &value) {
it_assert_debug((value == 0) || (value == 1),
"bin::operator=(): value must be 0 or 1");
b = static_cast<char>(value);
}
void operator=(const bin &inbin) { b = inbin.b; }
void operator/=(const bin &inbin) { b |= inbin.b; }
void operator|=(const bin &inbin) { b |= inbin.b; }
bin operator/(const bin &inbin) const { return bin(b | inbin.b); }
bin operator|(const bin &inbin) const { return bin(b | inbin.b); }
void operator+=(const bin &inbin) { b ^= inbin.b; }
void operator^=(const bin &inbin) { b ^= inbin.b; }
bin operator+(const bin &inbin) const { return bin(b ^ inbin.b); }
bin operator^(const bin &inbin) const { return bin(b ^ inbin.b); }
void operator-=(const bin &inbin) { b ^= inbin.b; }
bin operator-(const bin &inbin) const { return bin(b ^ inbin.b); }
bin operator-() const { return bin(b); }
void operator*=(const bin &inbin) { b &= inbin.b; }
void operator&=(const bin &inbin) { b &= inbin.b; }
bin operator*(const bin &inbin) const { return bin(b & inbin.b); }
bin operator&(const bin &inbin) const { return bin(b & inbin.b); }
bin operator!(void) const { return bin(b ^ 1); }
bin operator~(void) const { return bin(b ^ 1); }
bool operator==(const bin &inbin) const { return b == inbin.b; }
bool operator==(const int &i) const { return b == i; }
bool operator!=(const bin &inbin) const { return b != inbin.b; }
bool operator!=(const int &i) const { return b != i; }
bool operator<(const bin &inbin) const { return b < inbin.b; }
bool operator<=(const bin &inbin) const { return b <= inbin.b; }
bool operator>(const bin &inbin) const { return b > inbin.b; }
bool operator>=(const bin &inbin) const { return b >= inbin.b; }
operator short() const { return static_cast<short>(b); }
operator int() const { return static_cast<int>(b); }
operator bool() const { return b != 0; }
operator float() const { return static_cast<float>(b); }
operator double() const { return static_cast<double>(b); }
char value() const { return b; }
private:
char b;
};
ITPP_EXPORT std::ostream &operator<<(std::ostream &output, const bin &inbin);
ITPP_EXPORT std::istream &operator>>(std::istream &input, bin &outbin);
inline bin abs(const bin &inbin) { return inbin; }
} // namespace itpp
namespace std // added 11/2005, EGL
{
inline int abs(const itpp::bin &inbin) { return inbin; }
} // namespace std
#endif // #ifndef BINARY_H
itpp::Array
General array class.
Definition array.h:105
itpp::bin
Binary arithmetic (boolean) class.
Definition binary.h:57
itpp::bin::abs
bin abs(const bin &inbin)
absolute value of bin
Definition binary.h:174
itpp::bin::operator==
bool operator==(const bin &inbin) const
Check if equal.
Definition binary.h:121
itpp::bin::operator+=
void operator+=(const bin &inbin)
XOR.
Definition binary.h:92
itpp::bin::operator&=
void operator&=(const bin &inbin)
AND.
Definition binary.h:109
itpp::bin::operator&
bin operator&(const bin &inbin) const
AND.
Definition binary.h:113
itpp::bin::operator=
void operator=(const bin &inbin)
Assign a value.
Definition binary.h:79
itpp::bin::operator-
bin operator-() const
Dummy definition to be able to use vec<bin>
Definition binary.h:104
itpp::bin::operator!=
bool operator!=(const int &i) const
Check if not equal.
Definition binary.h:128
itpp::bin::operator<
bool operator<(const bin &inbin) const
Less than (interpret the binary values {0,1} as integers)
Definition binary.h:131
itpp::bin::operator^=
void operator^=(const bin &inbin)
XOR.
Definition binary.h:94
itpp::bin::operator-
bin operator-(const bin &inbin) const
XOR.
Definition binary.h:102
itpp::bin::operator>=
bool operator>=(const bin &inbin) const
Greater than equal (interpret the binary values {0,1} as integers)
Definition binary.h:138
itpp::bin::operator|
bin operator|(const bin &inbin) const
OR.
Definition binary.h:89
itpp::bin::operator*
bin operator*(const bin &inbin) const
AND.
Definition binary.h:111
itpp::bin::operator>
bool operator>(const bin &inbin) const
Greater than (interpret the binary values {0,1} as integers)
Definition binary.h:136
itpp::bin::operator/=
void operator/=(const bin &inbin)
OR.
Definition binary.h:82
itpp::bin::operator!
bin operator!(void) const
NOT.
Definition binary.h:116
itpp::bin::operator^
bin operator^(const bin &inbin) const
XOR.
Definition binary.h:98
itpp::bin::operator==
bool operator==(const int &i) const
Check if equal.
Definition binary.h:123
itpp::bin::operator+
bin operator+(const bin &inbin) const
XOR.
Definition binary.h:96
itpp::bin::operator<=
bool operator<=(const bin &inbin) const
Less than equal (interpret the binary values {0,1} as integers)
Definition binary.h:133
itpp::bin::operator-=
void operator-=(const bin &inbin)
XOR.
Definition binary.h:100
itpp::bin::operator*=
void operator*=(const bin &inbin)
AND.
Definition binary.h:107
itpp::bin::operator~
bin operator~(void) const
NOT.
Definition binary.h:118
itpp::bin::operator=
void operator=(const int &value)
Assign a value.
Definition binary.h:72
itpp::bin::bin
bin(const bin &inbin)
Copy constructor.
Definition binary.h:69
itpp::bin::operator|=
void operator|=(const bin &inbin)
OR.
Definition binary.h:85
itpp::bin::operator!=
bool operator!=(const bin &inbin) const
Check if not equal.
Definition binary.h:126
itpp::bin::value
char value() const
Output the binary value of the object.
Definition binary.h:152
itpp::bin::bin
bin()
Default constructor.
Definition binary.h:60
itpp::bin::operator/
bin operator/(const bin &inbin) const
OR.
Definition binary.h:87
itpp::bin::bin
bin(const int &value)
Set the binary object equal to value. Either "0" or "1".
Definition binary.h:63
it_assert_debug
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
Definition itassert.h:107
itassert.h
Error handling functions - header file.
itpp
itpp namespace
Definition itmex.h:37
itpp::operator<<
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Definition binary.cpp:36
itpp::operator>>
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
Definition binary.cpp:42
std
STL namespace.

Generated on Mon Jun 10 2024 11:49:16 for IT++ by Doxygen 1.9.8