30 #ifndef _DBINARY_BIN_H
31 #define _DBINARY_BIN_H
38 #include "Core/include/private/DTypes.hpp"
39 #include "Core/include/private/DMemory.hpp"
48 typedef UINT8 BIN_TYPE;
50 typedef UINT8 BIN_TYPE;
61 (*byte) |= (1UL<<
index);
63 (*
byte) &= ~(1UL<<
index);
68 return (*
byte) & (1UL<<
index);
76 BIN(BIN_TYPE v = numeric_limits<BIN_TYPE>::min()) : val(v) {}
77 BIN(
bool b) : val(b ? this->max() : this->min()) {}
78 BIN(
double v) : val(v==0 ? this->min() : this->max()) {}
80 static const BIN_TYPE SIZE =
sizeof(BIN_TYPE)*CHAR_BIT;
82 static inline BIN_TYPE min() {
return numeric_limits<BIN_TYPE>::min(); }
83 static inline BIN_TYPE max() {
return numeric_limits<BIN_TYPE>::max(); }
86 static const BIN_TYPE MS_BIT = (1UL << (SIZE - 2));
88 static const BIN_TYPE LS_BIT = 0x01;
91 typedef BIN_TYPE Type;
92 typedef Type *lineType;
93 typedef lineType *sliceType;
95 static inline BIN_TYPE binLen(BIN_TYPE bitCount) {
return (bitCount-1)/BIN::SIZE + 1; }
97 inline bitIndex& operator[] (UINT8 pos)
104 ostream& printSelf(ostream &os=cout)
106 for (
int i=0;i<SIZE;i++)
107 os << this->
operator[](i) <<
" ";
110 inline BIN& operator=(BIN_TYPE v)
115 inline BIN& operator=(
bool b)
117 val = b ? this->max() : this->min();
120 inline BIN& operator=(
const char* s)
122 UINT iMax = strlen(s) < SIZE ? strlen(s) : SIZE;
125 for (UINT i=0;i<iMax;i++)
126 val += (s[i]-48) * (1<<i);
135 inline ostream& operator << (ostream &os, BIN &b)
137 return b.printSelf(os);