checksum v0.1.0 Checksum.Helpers

Summary

Functions

Calculates a bit mask of ones with a length of width

Reorder the bits of a binary sequence value, by reflecting them about the middle position

Conditional Reorder the bits of a binary sequence, by reflecting them about the middle position. If bool is true the bits will be reflected, if it is false the input value will be returned

Calculates a top bit mask

Functions

bits_mask(width)

Calculates a bit mask of ones with a length of width.

Examples

iex> Checksum.Helpers.bits_mask(1) |> Integer.to_charlist(2)
'1'
iex> Checksum.Helpers.bits_mask(4) |> Integer.to_charlist(2)
'1111'
iex> Checksum.Helpers.bits_mask(8) |> Integer.to_charlist(2)
'11111111'
reflect(value, bits)

Reorder the bits of a binary sequence value, by reflecting them about the middle position.

Examples

iex> Checksum.Helpers.reflect(0x3E23, 3) == 0x3E26
true
reflect(value, bits, bool)

Conditional Reorder the bits of a binary sequence, by reflecting them about the middle position. If bool is true the bits will be reflected, if it is false the input value will be returned.

Examples

iex> Checksum.Helpers.reflect(0x3E23, 3, true) == 0x3E26
true
iex> Checksum.Helpers.reflect(0x3E23, 3, false) == 0x3E23
true
top_bit(width)

Calculates a top bit mask.

Examples

iex> Checksum.Helpers.top_bit(1) |> Integer.to_charlist(2)
'1'
iex> Checksum.Helpers.top_bit(4) |> Integer.to_charlist(2)
'1000'
iex> Checksum.Helpers.top_bit(8) |> Integer.to_charlist(2)
'10000000'