PHPackages                             vinicciusguedes/laravel-bitwise - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. vinicciusguedes/laravel-bitwise

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vinicciusguedes/laravel-bitwise
===============================

Pacote para facilitar a manipulação de números usando operações bitwise no Laravel.

1.1.2(1y ago)315MITPHPPHP ^7.2|^8.0CI passing

Since Jan 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/vinicciusguedes/laravel-bitwise)[ Packagist](https://packagist.org/packages/vinicciusguedes/laravel-bitwise)[ Docs](https://github.com/vinicciusguedes/laravel-bitwise)[ GitHub Sponsors](https://github.com/vinicciusguedes)[ RSS](/packages/vinicciusguedes-laravel-bitwise/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

Laravel Bitwise
===============

[](#laravel-bitwise)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ff17d536048b1f3ed7c1fbf8855627668fa7f6f57eba48abe7947e4c5fdd9e24/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76696e6963636975736775656465732f6c61726176656c2d626974776973652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vinicciusguedes/laravel-bitwise/)[![GitHub Workflow Status](https://camo.githubusercontent.com/f27a0ea5cf1b98865a31d5003704f04cbf59ec263ef505e99e0821e910a47447/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f76696e6963636975736775656465732f6c61726176656c2d626974776973652f6275696c642e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/vinicciusguedes/laravel-bitwise/actions)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

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
----------

[](#instalação)

### Instalar via Composer

[](#instalar-via-composer)

Você pode instalar o pacote através do Composer:

```
composer require vinicciusguedes/laravel-bitwise
```

Compatibilidade: Laravel e PHP
------------------------------

[](#compatibilidade-laravel-e-php)

Esta tabela mostra as versões do Laravel e suas versões compatíveis com o PHP.

LaravelPHP12.\*8.4, 8.3, 8.211.\*8.4, 8.3, 8.210.\*8.4, 8.3, 8.2, 8.1, 8.09.\*8.4, 8.3, 8.2, 8.1, 8.08.\*8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.37.\*8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.26.\*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
---------------

[](#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
-------------------

[](#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 (&amp; ~).
- Removes a specific bit from the current value using the AND NOT (&amp; ~) 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 (&amp; ~).
- Removes all provided bits in the current value using the AND NOT (&amp; ~) 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 (&amp;).
- Checks if a specific bit is active in the current value using the AND (&amp;) 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

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance45

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Total

3

Last Release

431d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d3dee19618a564dc9070eab025cb1299d624c60bb0a718c7c8f8ba4e81438a76?d=identicon)[vinicciusguedes](/maintainers/vinicciusguedes)

---

Top Contributors

[![vinicciusguedes](https://avatars.githubusercontent.com/u/24725482?v=4)](https://github.com/vinicciusguedes "vinicciusguedes (6 commits)")

---

Tags

bitbitwiselaravellaravel-frameworkphpphp-libraryphplaravel-packagesbitwisevinicciusguedeslaravel-bitwise

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/vinicciusguedes-laravel-bitwise/health.svg)

```
[![Health](https://phpackages.com/badges/vinicciusguedes-laravel-bitwise/health.svg)](https://phpackages.com/packages/vinicciusguedes-laravel-bitwise)
```

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[monicahq/laravel-cloudflare

Add Cloudflare ip addresses to trusted proxies for Laravel.

3372.7M4](/packages/monicahq-laravel-cloudflare)[kra8/laravel-snowflake

Snowflake for Laravel and Lumen.

188402.3k6](/packages/kra8-laravel-snowflake)[bezhansalleh/filament-google-analytics

Google Analytics integration for FilamentPHP

205144.8k5](/packages/bezhansalleh-filament-google-analytics)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[napp/xray-laravel

AWS X-Ray for Laravel applications.

61407.3k](/packages/napp-xray-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
