-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitVector.cpp
More file actions
140 lines (131 loc) · 2.34 KB
/
BitVector.cpp
File metadata and controls
140 lines (131 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "BitVector.h"
#include<QDebug>
BitVector::BitVector()
{
this->biTvector.resize(2000);
size=0;
}
void BitVector::setbit(int pos, int value)
{
bool boolReturn;
if(value == 0)
{
boolReturn = false;
}
else
{
boolReturn = true;
}
biTvector.setBit(pos,boolReturn);
if(pos>size)
{
size=pos;
}
}
void BitVector::setbit(QString value, int sizemax, int pos )
{
if(sizemax==0)
{
sizemax=value.size();
}
if(pos == -1)
{
pos = size;
}
int i=sizemax-value.size();
int j;
for(j = 0; j < value.size();j++)
{
if(value.at(j)=='0')
{
biTvector[pos+i+j] = false;
}
if(value.at(j)=='1')
{
biTvector[pos+i+j] = true;
}
}
size=pos+i+j;
}
int BitVector::bitVectorAt(int pos)
{
int boolReturn;
if(biTvector.at(pos))
{
boolReturn = 1;
}
else
{
boolReturn = 0;
}
return boolReturn;
}
QString BitVector::getQbitarray(bool WithTrash)
{
unsigned int bit;
QString bitReturn=QString();
int i= 0;
while(size-i>=8)
{
bit = 0x0000;
for(int j= 0; j<8;j++ )
{
if (biTvector[i+j])
{
bit = (bit<<1)|1;
}
else
{
bit = bit<<1;
}
}
i=i+8;
//qDebug()<<"bit numero "<<i<<" :"<<QString().setNum(bit,2);
bitReturn.append(bit);
}
if(WithTrash)
{
bit= 0;
for(int j= 0; j<size-i;j++ )
{
if (biTvector[i+j])
{
bit = (bit<<1)|1;
}
else
{
bit = bit<<1;
}
}
bit = bit<<(8-(size-i));
bitReturn.append(bit);
}
return bitReturn;
}
void BitVector::clearBitVector()
{
biTvector.clear();
this->biTvector.resize(2000);
size=0;
}
int BitVector::getSize()
{
return this->size;
}
void BitVector::resize()
{
int position=size%8;
QBitArray buffer;
buffer.resize(2000);
for(int i=0; i<position;i++)
{
buffer[i]=this->bitVectorAt(size-position+i);
}
biTvector.clear();
this->biTvector=buffer;
this->size=position;
}
void BitVector::setSize(int size)
{
this->size=size;
}