libschc
Macros | Functions
bit_operations.h File Reference
#include <stdint.h>
#include "schc.h"

Go to the source code of this file.

Macros

#define BYTES_TO_BITS(x)   (x * 8)
 
#define BITS_TO_BYTES(x)   (((x) == 0) ? 0 : (((x) - 1) / 8 + 1))
 

Functions

void set_bits (uint8_t A[], uint32_t pos, uint32_t len)
 sets bits at a certain position in a bit array big endian More...
 
uint32_t get_bits (const uint8_t A[], uint32_t pos, uint8_t len)
 get bits at a certain position in a bit array More...
 
void clear_bits (uint8_t A[], uint32_t pos, uint32_t len)
 clear bits at a certain position in a bit array big endian More...
 
void copy_bits (uint8_t DST[], uint32_t dst_pos, const uint8_t SRC[], uint32_t src_pos, uint32_t len)
 copy bits to a certain position in a bit array from another array big endian More...
 
uint8_t compare_bits (const uint8_t SRC1[], const uint8_t SRC2[], uint32_t len)
 compare two bit arrays More...
 
uint8_t compare_bits_aligned (const uint8_t SRC1[], uint16_t pos1, const uint8_t SRC2[], uint16_t pos2, uint32_t len)
 compare two bit arrays with starting point More...
 
uint8_t compare_bits_BIG_END (uint8_t SRC1[], uint8_t SRC2[], uint32_t len)
 
void shift_bits_left (uint8_t SRC[], uint16_t len, uint32_t shift)
 shift a number of bits to the left More...
 
void shift_bits_right (uint8_t SRC[], uint16_t len, uint32_t shift)
 shift a number of bits to the right More...
 
void xor_bits (uint8_t DST[], uint8_t SRC1[], uint8_t SRC2[], uint32_t len)
 logical XOR two bit arrays More...
 
void and_bits (uint8_t DST[], uint8_t SRC1[], uint8_t SRC2[], uint32_t len)
 logical AND two bit arrays More...
 
void print_bitmap (const uint8_t bitmap[], uint32_t length)
 print a bitmap More...
 
uint8_t get_number_of_bytes_from_bits (uint16_t number_of_bits)
 get the number of bytes required to store this amount of bits More...
 
uint32_t get_required_number_of_bits (uint32_t value)
 get the number of bits required to store a value More...
 
uint8_t get_position_in_first_byte (uint8_t value)
 get the starting bit of a value More...
 
uint8_t padded (schc_bitarray_t *bit_array)
 remove padding More...
 

Macro Definition Documentation

◆ BITS_TO_BYTES

#define BITS_TO_BYTES (   x)    (((x) == 0) ? 0 : (((x) - 1) / 8 + 1))

◆ BYTES_TO_BITS

#define BYTES_TO_BITS (   x)    (x * 8)

Function Documentation

◆ and_bits()

void and_bits ( uint8_t  DST[],
uint8_t  SRC1[],
uint8_t  SRC2[],
uint32_t  len 
)

logical AND two bit arrays

Parameters
DSTthe array to save the result in
SRC1the array to compare with
SRC2the array to compare with
lenthe number of consecutive bits to compare

◆ clear_bits()

void clear_bits ( uint8_t  A[],
uint32_t  pos,
uint32_t  len 
)

clear bits at a certain position in a bit array big endian

Parameters
Athe bit array
poswhich bit to clear
lenthe number of consecutive bits to clear

◆ compare_bits()

uint8_t compare_bits ( const uint8_t  SRC1[],
const uint8_t  SRC2[],
uint32_t  len 
)

compare two bit arrays

Parameters
SRC1the array to compare
SRC2the array to compare with
lenthe number of consecutive bits to compare
Returns
1 both arrays match 0 the arrays differ

◆ compare_bits_aligned()

uint8_t compare_bits_aligned ( const uint8_t  SRC1[],
uint16_t  pos1,
const uint8_t  SRC2[],
uint16_t  pos2,
uint32_t  len 
)

compare two bit arrays with starting point

Parameters
SRC1the array to compare
pos1position to start for src1
SRC2the array to compare with
pos2position to start for src2
lenthe number of consecutive bits to compare
Returns
1 both arrays match 0 the arrays differ

◆ compare_bits_BIG_END()

uint8_t compare_bits_BIG_END ( uint8_t  SRC1[],
uint8_t  SRC2[],
uint32_t  len 
)

◆ copy_bits()

void copy_bits ( uint8_t  DST[],
uint32_t  dst_pos,
const uint8_t  SRC[],
uint32_t  src_pos,
uint32_t  len 
)

copy bits to a certain position in a bit array from another array big endian

Parameters
DSTthe array to copy to
dst_poswhich bit to start from
SRCthe array to copy from
src_poswhich bit to start from
lenthe number of consecutive bits to set

◆ get_bits()

uint32_t get_bits ( const uint8_t  A[],
uint32_t  pos,
uint8_t  len 
)

get bits at a certain position in a bit array

Parameters
Athe bit array
posthe position to start from
lenthe number of consecutive bits to get
Note
limited to 32 consecutive bits

◆ get_number_of_bytes_from_bits()

uint8_t get_number_of_bytes_from_bits ( uint16_t  number_of_bits)

get the number of bytes required to store this amount of bits

Parameters
number_of_bitsthe number of bits to find the number of bytes for

◆ get_position_in_first_byte()

uint8_t get_position_in_first_byte ( uint8_t  value)

get the starting bit of a value

Parameters
valuethe value to count the number of bits for

◆ get_required_number_of_bits()

uint32_t get_required_number_of_bits ( uint32_t  n)

get the number of bits required to store a value

Parameters
valuethe value to count the number of bits for

◆ padded()

uint8_t padded ( schc_bitarray_t bit_array)

remove padding

Parameters
bit_arrthe bit array to remove padding for
Returns
1 remove the last byte 0 word aligned

◆ print_bitmap()

void print_bitmap ( const uint8_t  bitmap[],
uint32_t  length 
)

print a bitmap

Parameters
bitmapthe bit array
lenthe number of consecutive bits to print

◆ set_bits()

void set_bits ( uint8_t  A[],
uint32_t  pos,
uint32_t  len 
)

sets bits at a certain position in a bit array big endian

Parameters
Athe bit array
poswhich bit to set
lenthe number of consecutive bits to set

◆ shift_bits_left()

void shift_bits_left ( uint8_t  SRC[],
uint16_t  len,
uint32_t  shift 
)

shift a number of bits to the left

Parameters
SRCthe array to shift
lenthe length of the array
shiftthe number of consecutive bits to shift

◆ shift_bits_right()

void shift_bits_right ( uint8_t  SRC[],
uint16_t  len,
uint32_t  shift 
)

shift a number of bits to the right

Parameters
SRCthe array to shift
lenthe length of the array
shiftthe number of consecutive bits to shift

◆ xor_bits()

void xor_bits ( uint8_t  DST[],
uint8_t  SRC1[],
uint8_t  SRC2[],
uint32_t  len 
)

logical XOR two bit arrays

Parameters
DSTthe array to save the result in
SRC1the array to compare with
SRC2the array to compare with
lenthe number of consecutive bits to compare