@ticatec/node-common-library
Version:
A comprehensive Node.js database access framework providing robust abstractions for database connection management, SQL execution, transaction handling, pagination, and dynamic query building.
65 lines • 1.7 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
class BitsBoolean {
constructor(value = 0) {
this.value = Math.floor(value);
}
/**
* 将指定位置的位设置为true或false
* @param pos - 位位置(0-31)
* @param value - 要设置的布尔值
* @protected
*/
setBitValue(pos, value) {
if (pos < 0 || pos > 31) {
throw new Error("invalid bit pos.");
}
if (value) {
this.value |= (1 << pos);
}
else {
this.value &= ~(1 << pos);
}
}
/**
* 读取指定位置的位值
* @param pos - 位位置(0-31)
* @protected
* @returns 指定位置的布尔值
*/
getBitValue(pos) {
if (pos < 0 || pos > 31) {
throw new Error("invalid bit pos.");
}
return (this.value & (1 << pos)) !== 0;
}
/**
* 从布尔数组创建位值
* @param boolArray - 布尔值数组
* @static
* @returns 位操作后的数值
*/
static fromBooleanArray(boolArray) {
let result = 0;
for (let i = 0; i < boolArray.length; i++) {
if (boolArray[i]) {
result |= (1 << i);
}
}
return result;
}
/**
* 将位值转换为布尔数组
* @param length - 输出数组的长度
* @returns 布尔值数组
*/
toBooleanArray(length) {
const result = [];
for (let i = 0; i < length; i++) {
result.push(this.getBitValue(i));
}
return result;
}
}
exports.default = BitsBoolean;
//# sourceMappingURL=BitsBoolean.js.map
;