vinicciusguedes/laravel-bitwise
Composer 安装命令:
composer require vinicciusguedes/laravel-bitwise
包简介
Pacote para facilitar a manipulação de números usando operações bitwise no Laravel.
README 文档
README
Pacote para facilitar a manipulação de números usando operações bitwise no Laravel. Ideal para casos de uso como gerenciamento de permissões e flags, fornecendo funções para verificar, ativar, desativar e inverter bits de forma simples e eficiente.
Instalação
Instalar via Composer
Você pode instalar o pacote através do Composer:
composer require vinicciusguedes/laravel-bitwise
Compatibilidade: Laravel e PHP
Esta tabela mostra as versões do Laravel e suas versões compatíveis com o PHP.
| Laravel | PHP |
|---|---|
| 12.* | 8.4, 8.3, 8.2 |
| 11.* | 8.4, 8.3, 8.2 |
| 10.* | 8.4, 8.3, 8.2, 8.1, 8.0 |
| 9.* | 8.4, 8.3, 8.2, 8.1, 8.0 |
| 8.* | 8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.3 |
| 7.* | 8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2 |
| 6.* | 8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2 |
A tabela de compatibilidade pode ser ajustada de acordo com novas atualizações de versões do PHP ou Laravel.
Funcionalidades
O pacote oferece funções úteis para trabalhar com operações bitwise, como:
- Adiciona um bit a um valor atual
- Remove um bit de um valor
- Verifica se um bit está ativo
- Obtém todos os bits ativos de um valor
- Manipula bits em arrays
Funções Disponíveis
✅ addBit(int $currentValue, int $bit): int
- Adiciona um bit ao valor atual usando a operação OR (|).
- Adds a specific bit to the current value using the OR (|) operation.
$currentValue = 5; // 0101 em binário $bitToAdd = 2; // 0010 em binário $newValue = Bitwise::addBit($currentValue, $bitToAdd); // 7 (0111 em binário)
✅ addBits(int $currentValue, int $bit): int
- Adiciona todos os bits fornecidos no valor atual usando operação OR (|).
- Adds all provided bits in the current value using the OR (|) operation.
$currentValue = 5; // 0101 em binário $bitToAdd = [2, 4]; $newValue = Bitwise::addBits($currentValue, $bitToAdd); // 7 (0111 em binário)
✅ removeBit(int $currentValue, int $bit): int
- Remove um bit específico do valor atual usando operação AND NOT (& ~).
- Removes a specific bit from the current value using the AND NOT (& ~) operation.
$currentValue = 7; // 0111 em binário $bitToRemove = 2; // 0010 em binário $newValue = Bitwise::removeBit($currentValue, $bitToRemove); // 5 (0101 em binário)
✅ removeBits(int $currentValue, array $bits): int
- Remove todos os bits fornecidos no valor atual usando operação AND NOT (& ~).
- Removes all provided bits in the current value using the AND NOT (& ~) operation.
$currentValue = 15; // 1111 em binário $bitToRemove = [1, 4]; $newValue = Bitwise::removeBits($currentValue, $bitToRemove); // 10 (1010 em binário)
✅ hasBit(int $currentValue, int $bit): bool
- Verifica se um bit específico está ativo no valor atual usando a operação AND (&).
- Checks if a specific bit is active in the current value using the AND (&) operation.
$currentValue = 5; // 0101 em binário $bitToCheck = 4; // 0100 em binário $isActive = Bitwise::hasBit($currentValue, $bitToCheck); // true
✅ hasAllBits(int $bitValue, array $bits): bool
- Verifica se todos os bits fornecidos estão ativos no valor.
- Checks if all the provided bits are active in the value.
$currentValue = 15; // 1111 em binário $bitsArray = [1, 2, 4]; $allBitsActive = Bitwise::hasAllBits($currentValue, $bitsArray); // true
✅ getActiveBits(int $value, bool $key_type = true, bool $order = true): array
- Retorna todos os bits ativos no valor fornecido.
- Returns an array of all active bits in the value.
$value = 7; // 0111 em binário $activeBits = Bitwise::getActiveBits($value); // [1, 2, 4]
✅ sumActiveBits(array $bits): int
- Retorna o valor total da soma dos bits ativos.
- Returns the total value of the sum of the active bits.
$bits = [1, 2, 4]; $sum = Bitwise::sumActiveBits($bits); // 7
✅ addBitInArray(array $array, int $bit, bool $key_type = true, bool $order = true): array
- Adiciona um bit a um array, garantindo que o valor seja único.
- Adds a bit to an array, ensuring it is not duplicated.
$bitsArray = [1, 2]; $newArray = Bitwise::addBitInArray($bitsArray, 4); // [1, 2, 4]
✅ hasBitsInArray(int $bitValue, array $bits): array
- Verifica se cada valor de um array está presente nos bits de um valor dado.
- Checks if each value in an array is present in the bits of a given value.
$bitValue = 7; // 0111 em binário $bitsToCheck = [1, 2, 4]; $results = Bitwise::hasBitsInArray($bitValue, $bitsToCheck); // [1 => true, 2 => true, 4 => true]
✅ sortBitsByKey(array $bits): array
- Ordena as chaves do array com base nas chaves.
- Sorts the keys of the array based on the keys.
$bitsToCheck = [4 => 4, 2 => 2, 1 => 1]; $results = Bitwise::sortBitsByKey($bitsToCheck); // [1 => 1, 2 => 2, 4 => 4]
✅ sortBitsByValue(array $bits): array
- Ordena array com base nos valores.
- Sorts the array based on the values.
$bitsToCheck = [4,2,1]; $results = Bitwise::sortBitsByValue($bitsToCheck); // [2 => 1, 1 => 2, 0 => 4]
✅ toBinaryString(int $value): string
- Converte um valor inteiro para uma string binária.
- Converts an integer value to a binary string.
$number = 5; $results = Bitwise::toBinaryString($number); // 101
✅ fromBinary(string $value): int
- Converte um valor binário de volta para inteiro.
- Convert a binary value back to integer.
$number = "101"; $results = Bitwise::fromBinary($number); // 5
✅ function invertBit(int $value): int
- Inverte bit do valor.
- Invert the value bit.
$bit = 1; $results = Bitwise::invertBit($bit); // 0
Desenvolvedor: Viníccius Guedes
vinicciusguedes/laravel-bitwise 适用场景与选型建议
vinicciusguedes/laravel-bitwise 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 01 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「bitwise」 「laravel-packages」 「vinicciusguedes」 「laravel-bitwise」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vinicciusguedes/laravel-bitwise 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vinicciusguedes/laravel-bitwise 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vinicciusguedes/laravel-bitwise 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Helper for Laravel Development
Laravel Testing Helper for Packages Development
Workbench Companion for Laravel Packages Development
Useful class for binary operations
Enum Component
Bitwise flag setting for Yii 2.x
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-18