Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mnishiguchi/bit_flagger
Manipulate bit flags in Elixir
https://github.com/mnishiguchi/bit_flagger
bit-flag bitflag bitflags elixir elixir-lang elixir-programming-language
Last synced: about 1 month ago
JSON representation
Manipulate bit flags in Elixir
- Host: GitHub
- URL: https://github.com/mnishiguchi/bit_flagger
- Owner: mnishiguchi
- License: mit
- Created: 2021-09-03T19:49:00.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-09-05T00:46:01.000Z (over 3 years ago)
- Last Synced: 2024-10-30T21:39:00.407Z (about 2 months ago)
- Topics: bit-flag, bitflag, bitflags, elixir, elixir-lang, elixir-programming-language
- Language: Elixir
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# BitFlagger
[![Hex version](https://img.shields.io/hexpm/v/bit_flagger.svg 'Hex version')](https://hex.pm/packages/bit_flagger)
[![API docs](https://img.shields.io/hexpm/v/bit_flagger.svg?label=docs 'API docs')](https://hexdocs.pm/bit_flagger)
[![CI](https://github.com/mnishiguchi/bit_flagger/actions/workflows/ci.yml/badge.svg)](https://github.com/mnishiguchi/bit_flagger/actions/workflows/ci.yml)Manipulate bit flags in Elixir.
## Usage
```elixir
# Let's say we want to remember certain days of week as a single integer
iex> days_of_week = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]# The number of bit flags
iex> size = 7# All the days of the week are 127, no day of the week is the value 0
iex> state = 0b0000000
0iex> BitFlagger.parse(state, size)
[false, false, false, false, false, false, false]# Turn on the flags at index 1 (Monday) and 3 (Wednesday)
iex> state = state |> BitFlagger.on(1) |> BitFlagger.on(3)
10iex> BitFlagger.parse(state, size)
[false, true, false, true, false, false, false]# Turn off the flag at index 1 (Monday)
iex> state = BitFlagger.off(state, 1)
8iex> BitFlagger.parse(state, size)
[false, false, false, true, false, false, false]# We can easily make it human readable
iex> Enum.zip(days_of_week, BitFlagger.parse(state, size))
[
sunday: false,
monday: false,
tuesday: false,
wednesday: true,
thursday: false,
friday: false,
saturday: false
]
```## Installation
Add `bit_flagger` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:bit_flagger, "~> 0.1.0"}
]
end
```Documentation can be found at [https://hexdocs.pm/bit_flagger](https://hexdocs.pm/bit_flagger).