## Overview

`bitfield`

is a module for manipulating arrays of bits,
i.e. series of zeroes and ones spread across an
array of storage units (unsigned 32-bit integers).

### BitField Structure

Bit arrays are stored in data structures called 'BitField'. The structure is 'opaque', i.e. its internals are not available to the end user. This module provides API (functions and methods) for accessing and modifying bit arrays.

## Aliases

This section is empty.

## Constants

This section is empty.

## Sum types

This section is empty.

## Functions

bf_not toggles all bits in a bit array and returns the result as a new array.

bf_or performs logical OR operation on every pair of bits from 'input1' and 'input2' and returns the result as a new array. If inputs differ in size, the tail of the longer one is ignored.

bf_xor perform logical XOR operation on every pair of bits from 'input1' and 'input2' and returns the result as a new array. If inputs differ in size, the tail of the longer one is ignored.

from_bytes converts a byte array into a bitfield.

[0x0F, 0x01] => 0000 1111 0000 0001

from_bytes_lowest_bits_first converts a byte array into a bitfield [0x0F, 0x01] => 1111 0000 1000 0000

from_str converts a string of characters ('0' and '1') to a bit array. Any character different from '0' is treated as '1'.

hamming computes the Hamming distance between two bit arrays.

join concatenates two bit arrays and return the result as a new array.

## Structs

str converts the bit array to a string of characters ('0' and '1') and return the string

`fn (instance &BitField) free()`

frees the memory allocated for the bitfield instance

get_bit returns the value (0 or 1) of bit number 'bit_nr' (count from 0).

set_bit sets bit number 'bit_nr' to 1 (count from 0).

clear_bit clears (sets to zero) bit number 'bit_nr' (count from 0).

extract returns the value converted from a slice of bit numbers from 'start' by the length of 'len'.

0101 (1, 2) => 0b10

insert sets bit numbers from 'start' to 'len' length with the value converted from the number 'value'.

0000 (1, 2, 0b10) => 0100

extract returns the value converted from a slice of bit numbers from 'start' by the length of 'len'.

0101 (1, 2) => 0b01

insert sets bit numbers from 'start' to 'len' length with the value converted from the number 'value'.

0000 (1, 2, 0b10) => 0010

toggle_bit changes the value (from 0 to 1 or from 1 to 0) of bit number 'bit_nr'.

get_size returns the number of bits the array can hold.

clone creates a copy of a bit array.

== compares 2 bitfields, and returns true when they are equal

pop_count returns the number of set bits (ones) in the array.

pos checks if the array contains a sub-array 'needle' and returns its position if it does, -1 if it does not, and -2 on error.

slice returns a sub-array of bits between 'start_bit_nr' (included) and 'end_bit_nr' (excluded).

reverse reverses the order of bits in the array (swap the first with the last, the second with the last but one and so on).

resize changes the size of the bit array to 'new_size'.

rotate circular-shifts the bits by 'offset' positions (move 'offset' bit to 0, 'offset+1' bit to 1, and so on).

## Interfaces

This section is empty.

## Enums

This section is empty.

bf_and performs logical AND operation on every pair of bits from 'input1' and 'input2' and returns the result as a new array. If inputs differ in size, the tail of the longer one is ignored.