Skip to content

Instantly share code, notes, and snippets.

@ryochin
Last active June 19, 2023 02:25
Show Gist options
  • Save ryochin/804c0c8f22f8de277566a9034733301e to your computer and use it in GitHub Desktop.
Save ryochin/804c0c8f22f8de277566a9034733301e to your computer and use it in GitHub Desktop.
Elixir: 与えられた数値の指定されたビットの値を読み出す
import Bitwise
@doc """
与えられた数値の指定されたビットの値を読み出す
### Example
```
iex> bit_at(42, 3)
true
```
"""
@spec bit_at(non_neg_integer, non_neg_integer) :: boolean
def bit_at(uint8, at) when (uint8 &&& 1 <<< at) == 0, do: false
def bit_at(_, _), do: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment