def
__and__
(, arg__2)
def
__and__
(, arg__2)
def
__eq__
(other)
def
__getitem__
()
def
__iand__
(arg__1)
def
__ior__
(arg__1)
def
__ixor__
(arg__1)
def
__len__
()
def
__ne__
(other)
def
__or__
(, arg__2)
def
__setitem__
()
def
__xor__
(, arg__2)
def
at
(i)
def
bits
()
def
clear
()
def
clearBit
(i)
def
count
()
def
count
(on)
def
fill
(val, first, last)
def
fill
(val[, size=-1])
def
isEmpty
()
def
isNull
()
def
operator[]
(i)
def
operator[]
(i)
def
operator~
()
def
resize
(size)
def
setBit
(i)
def
setBit
(i, val)
def
size
()
def
swap
(other)
def
testBit
(i)
def
toggleBit
(i)
def
truncate
(pos)
A
QBitArrayis an array that gives access to individual bits and provides operators (AND,OR,XOR,和NOT) that work on entire arrays of bits. It uses 隐式共享 (copy-on-write) to reduce memory usage and to avoid the needless copying of data.The following code constructs a
QBitArraycontaining 200 bits initialized to false (0):ba = QBitArray(200)To initialize the bits to true, either pass
trueas second argument to the constructor, or callfill()later on.
QBitArrayuses 0-based indexes, just like C++ arrays. To access the bit at a particular index position, you can use operator[](). On non-const bit arrays, operator[]() returns a reference to a bit that can be used on the left side of an assignment. For example:ba = QBitArray() ba.resize(3) ba[0] = True ba[1] = False ba[2] = TrueFor technical reasons, it is more efficient to use
testBit()andsetBit()to access bits in the array than operator[](). For example:ba = QBitArray(3) ba.setBit(0, True) ba.setBit(1, False) ba.setBit(2, True)
QBitArraysupports&(AND),|(OR),^(XOR),~(NOT), as well as&=,|=,和^=. These operators work in the same way as the built-in C++ bitwise operators of the same name. For example:x = QBitArray(5) x.setBit(3, True) # x: [ 0, 0, 0, 1, 0 ] y = QBitArray(5) y.setBit(4, True) # y: [ 0, 0, 0, 0, 1 ] x |= y # x: [ 0, 0, 0, 1, 1 ]For historical reasons,
QBitArraydistinguishes between a null bit array and an empty bit array. A null bit array is a bit array that is initialized usingQBitArray‘s default constructor. An empty bit array is any bit array with size 0. A null bit array is always empty, but an empty bit array isn’t necessarily null:QBitArray().isNull() # returns True QBitArray().isEmpty() # returns True QBitArray(0).isNull() # returns False QBitArray(0).isEmpty() # returns True QBitArray(3).isNull() # returns False QBitArray(3).isEmpty() # returns FalseAll functions except
isNull()treat null bit arrays the same as empty bit arrays; for example,QBitArray()compares equal toQBitArray(0). We recommend that you always useisEmpty()and avoidisNull().另请参阅
QByteArrayQVector
QBitArray
¶
QBitArray(other)
QBitArray(size[, val=false])
- param size
int- param other
- param val
bool
Constructs an empty bit array.
另请参阅
Constructs a bit array containing
size
bits. The bits are initialized with
value
, which defaults to false (0).
PySide2.QtCore.QBitArray.
__getitem__
(
)
¶
PySide2.QtCore.QBitArray.
__len__
(
)
¶
PySide2.QtCore.QBitArray.
__setitem__
(
)
¶
PySide2.QtCore.QBitArray.
at
(
i
)
¶
i
–
int
bool
Returns the value of the bit at index position
i
.
i
must be a valid index position in the bit array (i.e., 0 <=
i
<
size()
).
另请参阅
operator[]()
PySide2.QtCore.QBitArray.
bits
(
)
¶
str
Returns a pointer to a dense bit array for this
QBitArray
. Bits are counted upwards from the least significant bit in each byte. The number of bits relevant in the last byte is given by
size()
%
8
.
另请参阅
PySide2.QtCore.QBitArray.
clear
(
)
¶
Clears the contents of the bit array and makes it empty.
PySide2.QtCore.QBitArray.
clearBit
(
i
)
¶
i
–
int
Sets the bit at index position
i
to 0.
i
must be a valid index position in the bit array (i.e., 0 <=
i
<
size()
).
另请参阅
PySide2.QtCore.QBitArray.
count
(
on
)
¶
on
–
bool
int
若
on
is true, this function returns the number of 1-bits stored in the bit array; otherwise the number of 0-bits is returned.
PySide2.QtCore.QBitArray.
fill
(
val
,
first
,
last
)
¶
val
–
bool
first
–
int
last
–
int
这是重载函数。
Sets bits at index positions
begin
up to (but not including)
end
to
value
.
begin
must be a valid index position in the bit array (0 <=
begin
<
size()
).
end
must be either a valid index position or equal to
size()
, in which case the fill operation runs until the end of the array (0 <=
end
<=
size()
).
范例:
QBitArray ba(4);
ba.fill(true, 1, 2); // ba: [ 0, 1, 0, 0 ]
ba.fill(true, 1, 3); // ba: [ 0, 1, 1, 0 ]
ba.fill(true, 1, 4); // ba: [ 0, 1, 1, 1 ]
PySide2.QtCore.QBitArray.
fill
(
val
[
,
size=-1
]
)
¶
val
–
bool
size
–
int
bool
Sets every bit in the bit array to
value
, returning true if successful; otherwise returns
false
。若
size
is different from -1 (the default), the bit array is resized to
size
beforehand.
范例:
ba = QBitArray(8)
ba.fill(True)
# ba: [ 1, 1, 1, 1, 1, 1, 1, 1 ]
ba.fill(False, 2)
# ba: [ 0, 0 ]
另请参阅
PySide2.QtCore.QBitArray.
fromBits
(
data
,
len
)
¶
data – str
len
–
long
long
创建
QBitArray
with the dense bit array located at
data
,采用
size
bits. The byte array at
data
must be at least
size
/ 8 (rounded up) bytes long.
若
size
is not a multiple of 8, this function will include the lowest
size
% 8 bits from the last byte in
data
.
另请参阅
PySide2.QtCore.QBitArray.
isEmpty
(
)
¶
bool
返回
true
if this bit array has size 0; otherwise returns false.
另请参阅
PySide2.QtCore.QBitArray.
isNull
(
)
¶
bool
返回
true
if this bit array is null; otherwise returns
false
.
范例:
QBitArray().isNull() # returns True
QBitArray(0).isNull() # returns False
QBitArray(3).isNull() # returns False
Qt makes a distinction between null bit arrays and empty bit arrays for historical reasons. For most applications, what matters is whether or not a bit array contains any data, and this can be determined using
isEmpty()
.
另请参阅
PySide2.QtCore.QBitArray.
__ne__
(
other
)
¶
other
–
QBitArray
bool
返回
true
if
other
is not equal to this bit array; otherwise returns
false
.
另请参阅
operator==()
PySide2.QtCore.QBitArray.
__eq__
(
other
)
¶
other
–
QBitArray
bool
返回
true
if
other
is equal to this bit array; otherwise returns
false
.
另请参阅
operator!=()
PySide2.QtCore.QBitArray.operator[](i)
i
–
int
bool
这是重载函数。
PySide2.QtCore.QBitArray.operator[](i)
i
–
uint
bool
这是重载函数。
PySide2.QtCore.QBitArray.
__ixor__
(
arg__1
)
¶
Performs the XOR operation between all bits in this bit array and
other
. Assigns the result to this bit array, and returns a reference to it.
The result has the length of the longest of the two bit arrays, with any missing bits (if one array is shorter than the other) taken to be 0.
范例:
a = QBitArray(3)
b = QBitArray(2)
a[0] = 1
a[1] = 0
a[2] = 1
# a: [ 1, 0, 1 ]
b[0] = 1
b[1] = 0
# b: [ 1, 1 ]
a ^= b
# a: [ 0, 1, 1 ]
另请参阅
operator^()
operator&=()
operator|=()
operator~()
PySide2.QtCore.QBitArray.
__ior__
(
arg__1
)
¶
Performs the OR operation between all bits in this bit array and
other
. Assigns the result to this bit array, and returns a reference to it.
The result has the length of the longest of the two bit arrays, with any missing bits (if one array is shorter than the other) taken to be 0.
范例:
a = QBitArray(3)
b = QBitArray(2)
a[0] = 1
a[1] = 0
a[2] = 1
# a: [ 1, 0, 1 ]
b[0] = 1
b[1] = 0
# b: [ 1, 1 ]
a |= b
# a: [ 1, 1, 1 ]
另请参阅
operator|()
operator&=()
operator^=()
operator~()
PySide2.QtCore.QBitArray.operator~()
Returns a bit array that contains the inverted bits of this bit array.
范例:
a = QBitArray(3)
b = QBitArray()
a[0] = 1
a[1] = 0
a[2] = 1
# a: [ 1, 0, 1 ]
b = ~a
# b: [ 0, 1, 0 ]
另请参阅
operator&()
operator|()
operator^()
PySide2.QtCore.QBitArray.
resize
(
size
)
¶
size
–
int
Resizes the bit array to
size
bits.
若
size
is greater than the current size, the bit array is extended to make it
size
bits with the extra bits added to the end. The new bits are initialized to false (0).
若
size
is less than the current size, bits are removed from the end.
另请参阅
PySide2.QtCore.QBitArray.
setBit
(
i
)
¶
i
–
int
Sets the bit at index position
i
to 1.
i
must be a valid index position in the bit array (i.e., 0 <=
i
<
size()
).
另请参阅
PySide2.QtCore.QBitArray.
setBit
(
i
,
val
)
¶
i
–
int
val
–
bool
这是重载函数。
Sets the bit at index position
i
to
value
.
PySide2.QtCore.QBitArray.
size
(
)
¶
int
Returns the number of bits stored in the bit array.
另请参阅
PySide2.QtCore.QBitArray.
swap
(
other
)
¶
other
–
QBitArray
Swaps bit array
other
with this bit array. This operation is very fast and never fails.
PySide2.QtCore.QBitArray.
testBit
(
i
)
¶
i
–
int
bool
返回
true
if the bit at index position
i
is 1; otherwise returns
false
.
i
must be a valid index position in the bit array (i.e., 0 <=
i
<
size()
).
另请参阅
PySide2.QtCore.QBitArray.
toggleBit
(
i
)
¶
i
–
int
bool
Inverts the value of the bit at index position
i
, returning the previous value of that bit as either true (if it was set) or false (if it was unset).
If the previous value was 0, the new value will be 1. If the previous value was 1, the new value will be 0.
i
must be a valid index position in the bit array (i.e., 0 <=
i
<
size()
).
另请参阅