bit_lib and nfc_util refactor (#3383)

* nfc_util functions for processing bytes moved into bit_lib
* bitlib test update
* bit_lib moved from lfrfid to standalone lib
* Added bit functions for any supported data types
* Error fix and api add
* Added test for 64
* Added doc
* Testcase for 64 rewrited
* Realization error fix
* API version bump
* sync api version, fix after-merge old libs usage
* fix build errors
* build fix
* fbt format

Co-authored-by: assasinfil <nfa57643@gmail.com>
Co-authored-by: gornekich <n.gorbadey@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Leptopt1los
2024-02-14 13:41:42 +09:00
committed by GitHub
parent a46038acbf
commit dd988ba449
55 changed files with 661 additions and 184 deletions

22
lib/bit_lib/SConscript Normal file
View File

@@ -0,0 +1,22 @@
Import("env")
env.Append(
LINT_SOURCES=[
Dir("."),
],
CPPPATH=[
"#/lib/bit_lib",
],
SDK_HEADERS=[
File("bit_lib.h"),
],
)
libenv = env.Clone(FW_LIB_NAME="bit_lib")
libenv.ApplyLibFlags()
sources = libenv.GlobRecursive("*.c*")
lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources)
libenv.Install("${LIB_DIST_DIR}", lib)
Return("lib")

485
lib/bit_lib/bit_lib.c Normal file
View File

@@ -0,0 +1,485 @@
#include "bit_lib.h"
#include <core/check.h>
#include <stdio.h>
void bit_lib_push_bit(uint8_t* data, size_t data_size, bool bit) {
size_t last_index = data_size - 1;
for(size_t i = 0; i < last_index; ++i) {
data[i] = (data[i] << 1) | ((data[i + 1] >> 7) & 1);
}
data[last_index] = (data[last_index] << 1) | bit;
}
void bit_lib_set_bit(uint8_t* data, size_t position, bool bit) {
if(bit) {
data[position / 8] |= 1UL << (7 - (position % 8));
} else {
data[position / 8] &= ~(1UL << (7 - (position % 8)));
}
}
void bit_lib_set_bits(uint8_t* data, size_t position, uint8_t byte, uint8_t length) {
furi_check(length <= 8);
furi_check(length > 0);
for(uint8_t i = 0; i < length; ++i) {
uint8_t shift = (length - 1) - i;
bit_lib_set_bit(data, position + i, (byte >> shift) & 1); //-V610
}
}
bool bit_lib_get_bit(const uint8_t* data, size_t position) {
return (data[position / 8] >> (7 - (position % 8))) & 1;
}
uint8_t bit_lib_get_bits(const uint8_t* data, size_t position, uint8_t length) {
uint8_t shift = position % 8;
if(shift == 0) {
return data[position / 8] >> (8 - length);
} else {
// TODO FL-3534: fix read out of bounds
uint8_t value = (data[position / 8] << (shift));
value |= data[position / 8 + 1] >> (8 - shift);
value = value >> (8 - length);
return value;
}
}
uint16_t bit_lib_get_bits_16(const uint8_t* data, size_t position, uint8_t length) {
uint16_t value = 0;
if(length <= 8) {
value = bit_lib_get_bits(data, position, length);
} else {
value = bit_lib_get_bits(data, position, 8) << (length - 8);
value |= bit_lib_get_bits(data, position + 8, length - 8);
}
return value;
}
uint32_t bit_lib_get_bits_32(const uint8_t* data, size_t position, uint8_t length) {
uint32_t value = 0;
if(length <= 8) {
value = bit_lib_get_bits(data, position, length);
} else if(length <= 16) {
value = bit_lib_get_bits(data, position, 8) << (length - 8);
value |= bit_lib_get_bits(data, position + 8, length - 8);
} else if(length <= 24) {
value = bit_lib_get_bits(data, position, 8) << (length - 8);
value |= bit_lib_get_bits(data, position + 8, 8) << (length - 16);
value |= bit_lib_get_bits(data, position + 16, length - 16);
} else {
value = (uint32_t)bit_lib_get_bits(data, position, 8) << (length - 8);
value |= (uint32_t)bit_lib_get_bits(data, position + 8, 8) << (length - 16);
value |= (uint32_t)bit_lib_get_bits(data, position + 16, 8) << (length - 24);
value |= bit_lib_get_bits(data, position + 24, length - 24);
}
return value;
}
uint64_t bit_lib_get_bits_64(const uint8_t* data, size_t position, uint8_t length) {
uint64_t value = 0;
if(length <= 8) {
value = bit_lib_get_bits(data, position, length);
} else if(length <= 16) {
value = bit_lib_get_bits(data, position, 8) << (length - 8);
value |= bit_lib_get_bits(data, position + 8, length - 8);
} else if(length <= 24) {
value = bit_lib_get_bits(data, position, 8) << (length - 8);
value |= bit_lib_get_bits(data, position + 8, 8) << (length - 16);
value |= bit_lib_get_bits(data, position + 16, length - 16);
} else if(length <= 32) {
value = (uint64_t)bit_lib_get_bits(data, position, 8) << (length - 8);
value |= (uint64_t)bit_lib_get_bits(data, position + 8, 8) << (length - 16);
value |= (uint64_t)bit_lib_get_bits(data, position + 16, 8) << (length - 24);
value |= bit_lib_get_bits(data, position + 24, length - 24);
} else if(length <= 40) {
value = (uint64_t)bit_lib_get_bits(data, position, 8) << (length - 8);
value |= (uint64_t)bit_lib_get_bits(data, position + 8, 8) << (length - 16);
value |= (uint64_t)bit_lib_get_bits(data, position + 16, 8) << (length - 24);
value |= (uint64_t)bit_lib_get_bits(data, position + 24, 8) << (length - 32);
value |= bit_lib_get_bits(data, position + 32, length - 32);
} else if(length <= 48) {
value = (uint64_t)bit_lib_get_bits(data, position, 8) << (length - 8);
value |= (uint64_t)bit_lib_get_bits(data, position + 8, 8) << (length - 16);
value |= (uint64_t)bit_lib_get_bits(data, position + 16, 8) << (length - 24);
value |= (uint64_t)bit_lib_get_bits(data, position + 24, 8) << (length - 32);
value |= (uint64_t)bit_lib_get_bits(data, position + 32, 8) << (length - 40);
value |= bit_lib_get_bits(data, position + 40, length - 40);
} else if(length <= 56) {
value = (uint64_t)bit_lib_get_bits(data, position, 8) << (length - 8);
value |= (uint64_t)bit_lib_get_bits(data, position + 8, 8) << (length - 16);
value |= (uint64_t)bit_lib_get_bits(data, position + 16, 8) << (length - 24);
value |= (uint64_t)bit_lib_get_bits(data, position + 24, 8) << (length - 32);
value |= (uint64_t)bit_lib_get_bits(data, position + 32, 8) << (length - 40);
value |= (uint64_t)bit_lib_get_bits(data, position + 40, 8) << (length - 48);
value |= bit_lib_get_bits(data, position + 48, length - 48);
} else {
value = (uint64_t)bit_lib_get_bits(data, position, 8) << (length - 8);
value |= (uint64_t)bit_lib_get_bits(data, position + 8, 8) << (length - 16);
value |= (uint64_t)bit_lib_get_bits(data, position + 16, 8) << (length - 24);
value |= (uint64_t)bit_lib_get_bits(data, position + 24, 8) << (length - 32);
value |= (uint64_t)bit_lib_get_bits(data, position + 32, 8) << (length - 40);
value |= (uint64_t)bit_lib_get_bits(data, position + 40, 8) << (length - 48);
value |= (uint64_t)bit_lib_get_bits(data, position + 48, 8) << (length - 56);
value |= bit_lib_get_bits(data, position + 56, length - 56);
}
return value;
}
bool bit_lib_test_parity_32(uint32_t bits, BitLibParity parity) {
#if !defined __GNUC__
#error Please, implement parity test for non-GCC compilers
#else
switch(parity) {
case BitLibParityEven:
return __builtin_parity(bits);
case BitLibParityOdd:
return !__builtin_parity(bits);
default:
furi_crash("Unknown parity");
}
#endif
}
bool bit_lib_test_parity(
const uint8_t* bits,
size_t position,
uint8_t length,
BitLibParity parity,
uint8_t parity_length) {
uint32_t parity_block;
bool result = true;
const size_t parity_blocks_count = length / parity_length;
for(size_t i = 0; i < parity_blocks_count; ++i) {
switch(parity) {
case BitLibParityEven:
case BitLibParityOdd:
parity_block = bit_lib_get_bits_32(bits, position + i * parity_length, parity_length);
if(!bit_lib_test_parity_32(parity_block, parity)) {
result = false;
}
break;
case BitLibParityAlways0:
if(bit_lib_get_bit(bits, position + i * parity_length + parity_length - 1)) {
result = false;
}
break;
case BitLibParityAlways1:
if(!bit_lib_get_bit(bits, position + i * parity_length + parity_length - 1)) {
result = false;
}
break;
}
if(!result) break;
}
return result;
}
size_t bit_lib_add_parity(
const uint8_t* data,
size_t position,
uint8_t* dest,
size_t dest_position,
uint8_t source_length,
uint8_t parity_length,
BitLibParity parity) {
uint32_t parity_word = 0;
size_t j = 0, bit_count = 0;
for(int word = 0; word < source_length; word += parity_length - 1) {
for(int bit = 0; bit < parity_length - 1; bit++) {
parity_word = (parity_word << 1) | bit_lib_get_bit(data, position + word + bit);
bit_lib_set_bit(
dest, dest_position + j++, bit_lib_get_bit(data, position + word + bit));
}
// if parity fails then return 0
switch(parity) {
case BitLibParityAlways0:
bit_lib_set_bit(dest, dest_position + j++, 0);
break; // marker bit which should be a 0
case BitLibParityAlways1:
bit_lib_set_bit(dest, dest_position + j++, 1);
break; // marker bit which should be a 1
default:
bit_lib_set_bit(
dest,
dest_position + j++,
(bit_lib_test_parity_32(parity_word, BitLibParityOdd) ^ parity) ^ 1);
break;
}
bit_count += parity_length;
parity_word = 0;
}
// if we got here then all the parities passed
// return bit count
return bit_count;
}
size_t bit_lib_remove_bit_every_nth(uint8_t* data, size_t position, uint8_t length, uint8_t n) {
size_t counter = 0;
size_t result_counter = 0;
uint8_t bit_buffer = 0;
uint8_t bit_counter = 0;
while(counter < length) {
if((counter + 1) % n != 0) {
bit_buffer = (bit_buffer << 1) | bit_lib_get_bit(data, position + counter);
bit_counter++;
}
if(bit_counter == 8) {
bit_lib_set_bits(data, position + result_counter, bit_buffer, 8);
bit_counter = 0;
bit_buffer = 0;
result_counter += 8;
}
counter++;
}
if(bit_counter != 0) {
bit_lib_set_bits(data, position + result_counter, bit_buffer, bit_counter);
result_counter += bit_counter;
}
return result_counter;
}
void bit_lib_copy_bits(
uint8_t* data,
size_t position,
size_t length,
const uint8_t* source,
size_t source_position) {
for(size_t i = 0; i < length; ++i) {
bit_lib_set_bit(data, position + i, bit_lib_get_bit(source, source_position + i));
}
}
void bit_lib_reverse_bits(uint8_t* data, size_t position, uint8_t length) {
size_t i = 0;
size_t j = length - 1;
while(i < j) {
bool tmp = bit_lib_get_bit(data, position + i);
bit_lib_set_bit(data, position + i, bit_lib_get_bit(data, position + j));
bit_lib_set_bit(data, position + j, tmp);
i++;
j--;
}
}
uint8_t bit_lib_get_bit_count(uint32_t data) {
#if defined __GNUC__
return __builtin_popcountl(data);
#else
#error Please, implement popcount for non-GCC compilers
#endif
}
void bit_lib_print_bits(const uint8_t* data, size_t length) {
for(size_t i = 0; i < length; ++i) {
printf("%u", bit_lib_get_bit(data, i));
}
}
void bit_lib_print_regions(
const BitLibRegion* regions,
size_t region_count,
const uint8_t* data,
size_t length) {
// print data
bit_lib_print_bits(data, length);
printf("\r\n");
// print regions
for(size_t c = 0; c < length; ++c) {
bool print = false;
for(size_t i = 0; i < region_count; i++) {
if(regions[i].start <= c && c < regions[i].start + regions[i].length) {
print = true;
printf("%c", regions[i].mark);
break;
}
}
if(!print) {
printf(" ");
}
}
printf("\r\n");
// print regions data
for(size_t c = 0; c < length; ++c) {
bool print = false;
for(size_t i = 0; i < region_count; i++) {
if(regions[i].start <= c && c < regions[i].start + regions[i].length) {
print = true;
printf("%u", bit_lib_get_bit(data, c));
break;
}
}
if(!print) {
printf(" ");
}
}
printf("\r\n");
}
uint16_t bit_lib_reverse_16_fast(uint16_t data) {
uint16_t result = 0;
result |= (data & 0x8000) >> 15;
result |= (data & 0x4000) >> 13;
result |= (data & 0x2000) >> 11;
result |= (data & 0x1000) >> 9;
result |= (data & 0x0800) >> 7;
result |= (data & 0x0400) >> 5;
result |= (data & 0x0200) >> 3;
result |= (data & 0x0100) >> 1;
result |= (data & 0x0080) << 1;
result |= (data & 0x0040) << 3;
result |= (data & 0x0020) << 5;
result |= (data & 0x0010) << 7;
result |= (data & 0x0008) << 9;
result |= (data & 0x0004) << 11;
result |= (data & 0x0002) << 13;
result |= (data & 0x0001) << 15;
return result;
}
uint8_t bit_lib_reverse_8_fast(uint8_t byte) {
byte = (byte & 0xF0) >> 4 | (byte & 0x0F) << 4;
byte = (byte & 0xCC) >> 2 | (byte & 0x33) << 2;
byte = (byte & 0xAA) >> 1 | (byte & 0x55) << 1;
return byte;
}
uint16_t bit_lib_crc8(
uint8_t const* data,
size_t data_size,
uint8_t polynom,
uint8_t init,
bool ref_in,
bool ref_out,
uint8_t xor_out) {
uint8_t crc = init;
for(size_t i = 0; i < data_size; ++i) {
uint8_t byte = data[i];
if(ref_in) bit_lib_reverse_bits(&byte, 0, 8);
crc ^= byte;
for(size_t j = 8; j > 0; --j) {
if(crc & TOPBIT(8)) {
crc = (crc << 1) ^ polynom;
} else {
crc = (crc << 1);
}
}
}
if(ref_out) bit_lib_reverse_bits(&crc, 0, 8);
crc ^= xor_out;
return crc;
}
uint16_t bit_lib_crc16(
uint8_t const* data,
size_t data_size,
uint16_t polynom,
uint16_t init,
bool ref_in,
bool ref_out,
uint16_t xor_out) {
uint16_t crc = init;
for(size_t i = 0; i < data_size; ++i) {
uint8_t byte = data[i];
if(ref_in) byte = bit_lib_reverse_16_fast(byte) >> 8;
for(size_t j = 0; j < 8; ++j) {
bool c15 = (crc >> 15 & 1);
bool bit = (byte >> (7 - j) & 1);
crc <<= 1;
if(c15 ^ bit) crc ^= polynom;
}
}
if(ref_out) crc = bit_lib_reverse_16_fast(crc);
crc ^= xor_out;
return crc;
}
void bit_lib_num_to_bytes_be(uint64_t src, uint8_t len, uint8_t* dest) {
furi_assert(dest);
furi_assert(len <= 8);
while(len--) {
dest[len] = (uint8_t)src;
src >>= 8;
}
}
void bit_lib_num_to_bytes_le(uint64_t src, uint8_t len, uint8_t* dest) {
furi_assert(dest);
furi_assert(len <= 8);
for(int i = 0; i < len; i++) {
dest[i] = (uint8_t)(src >> (8 * i));
}
}
uint64_t bit_lib_bytes_to_num_be(const uint8_t* src, uint8_t len) {
furi_assert(src);
furi_assert(len <= 8);
uint64_t res = 0;
while(len--) {
res = (res << 8) | (*src);
src++;
}
return res;
}
uint64_t bit_lib_bytes_to_num_le(const uint8_t* src, uint8_t len) {
furi_assert(src);
furi_assert(len <= 8);
uint64_t res = 0;
uint8_t shift = 0;
while(len--) {
res |= ((uint64_t)*src) << (8 * shift++);
src++;
}
return res;
}
uint64_t bit_lib_bytes_to_num_bcd(const uint8_t* src, uint8_t len, bool* is_bcd) {
furi_assert(src);
furi_assert(len <= 9);
uint64_t res = 0;
uint8_t nibble_1, nibble_2;
*is_bcd = true;
for(uint8_t i = 0; i < len; i++) {
nibble_1 = src[i] / 16;
nibble_2 = src[i] % 16;
if((nibble_1 > 9) || (nibble_2 > 9)) *is_bcd = false;
res *= 10;
res += nibble_1;
res *= 10;
res += nibble_2;
}
return res;
}

329
lib/bit_lib/bit_lib.h Normal file
View File

@@ -0,0 +1,329 @@
#pragma once
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TOPBIT(X) (1 << ((X)-1))
typedef enum {
BitLibParityEven,
BitLibParityOdd,
BitLibParityAlways0,
BitLibParityAlways1,
} BitLibParity;
/** @brief Increment and wrap around a value.
* @param index value to increment
* @param length wrap-around range
*/
#define bit_lib_increment_index(index, length) (index = (((index) + 1) % (length)))
/** @brief Test if a bit is set.
* @param data value to test
* @param index bit index to test
*/
#define bit_lib_bit_is_set(data, index) (((data) & (1 << (index))) != 0)
/** @brief Test if a bit is not set.
* @param data value to test
* @param index bit index to test
*/
#define bit_lib_bit_is_not_set(data, index) (((data) & (1 << (index))) == 0)
/** @brief Push a bit into a byte array.
* @param data array to push bit into
* @param data_size array size
* @param bit bit to push
*/
void bit_lib_push_bit(uint8_t* data, size_t data_size, bool bit);
/** @brief Set a bit in a byte array.
* @param data array to set bit in
* @param position The position of the bit to set.
* @param bit bit value to set
*/
void bit_lib_set_bit(uint8_t* data, size_t position, bool bit);
/** @brief Set the bit at the given position to the given value.
* @param data The data to set the bit in.
* @param position The position of the bit to set.
* @param byte The data to set the bit to.
* @param length The length of the data.
*/
void bit_lib_set_bits(uint8_t* data, size_t position, uint8_t byte, uint8_t length);
/** @brief Get the bit of a byte.
* @param data The byte to get the bits from.
* @param position The position of the bit.
* @return The bit.
*/
bool bit_lib_get_bit(const uint8_t* data, size_t position);
/**
* @brief Get the bits of a data, as uint8_t.
* @param data The data to get the bits from.
* @param position The position of the first bit.
* @param length The length of the bits.
* @return The bits.
*/
uint8_t bit_lib_get_bits(const uint8_t* data, size_t position, uint8_t length);
/**
* @brief Get the bits of a data, as uint16_t.
* @param data The data to get the bits from.
* @param position The position of the first bit.
* @param length The length of the bits.
* @return The bits.
*/
uint16_t bit_lib_get_bits_16(const uint8_t* data, size_t position, uint8_t length);
/**
* @brief Get the bits of a data, as uint32_t.
* @param data The data to get the bits from.
* @param position The position of the first bit.
* @param length The length of the bits.
* @return The bits.
*/
uint32_t bit_lib_get_bits_32(const uint8_t* data, size_t position, uint8_t length);
/**
* @brief Get the bits of a data, as uint64_t.
* @param data The data to get the bits from.
* @param position The position of the first bit.
* @param length The length of the bits.
* @return The bits.
*/
uint64_t bit_lib_get_bits_64(const uint8_t* data, size_t position, uint8_t length);
/**
* @brief Test parity of given bits
* @param bits Bits to test parity of
* @param parity Parity to test against
* @return true if parity is correct, false otherwise
*/
bool bit_lib_test_parity_32(uint32_t bits, BitLibParity parity);
/**
* @brief Test parity of bit array, check parity for every parity_length block from start
*
* @param data Bit array
* @param position Start position
* @param length Bit count
* @param parity Parity to test against
* @param parity_length Parity block length
* @return true
* @return false
*/
bool bit_lib_test_parity(
const uint8_t* data,
size_t position,
uint8_t length,
BitLibParity parity,
uint8_t parity_length);
/**
* @brief Add parity to bit array
*
* @param data Source bit array
* @param position Start position
* @param dest Destination bit array
* @param dest_position Destination position
* @param source_length Source bit count
* @param parity_length Parity block length
* @param parity Parity to test against
* @return size_t
*/
size_t bit_lib_add_parity(
const uint8_t* data,
size_t position,
uint8_t* dest,
size_t dest_position,
uint8_t source_length,
uint8_t parity_length,
BitLibParity parity);
/**
* @brief Remove bit every n in array and shift array left. Useful to remove parity.
*
* @param data Bit array
* @param position Start position
* @param length Bit count
* @param n every n bit will be removed
* @return size_t
*/
size_t bit_lib_remove_bit_every_nth(uint8_t* data, size_t position, uint8_t length, uint8_t n);
/**
* @brief Copy bits from source to destination.
*
* @param data destination array
* @param position position in destination array
* @param length length of bits to copy
* @param source source array
* @param source_position position in source array
*/
void bit_lib_copy_bits(
uint8_t* data,
size_t position,
size_t length,
const uint8_t* source,
size_t source_position);
/**
* @brief Reverse bits in bit array
*
* @param data Bit array
* @param position start position
* @param length length of bits to reverse
*/
void bit_lib_reverse_bits(uint8_t* data, size_t position, uint8_t length);
/**
* @brief Count 1 bits in data
*
* @param data
* @return uint8_t set bit count
*/
uint8_t bit_lib_get_bit_count(uint32_t data);
/**
* @brief Print data as bit array
*
* @param data
* @param length
*/
void bit_lib_print_bits(const uint8_t* data, size_t length);
typedef struct {
const char mark;
const size_t start;
const size_t length;
} BitLibRegion;
/**
* @brief Print data as bit array and mark regions. Regions needs to be sorted by start position.
*
* @param regions
* @param region_count
* @param data
* @param length
*/
void bit_lib_print_regions(
const BitLibRegion* regions,
size_t region_count,
const uint8_t* data,
size_t length);
/**
* @brief Reverse bits in uint16_t, faster than generic bit_lib_reverse_bits.
*
* @param data
* @return uint16_t
*/
uint16_t bit_lib_reverse_16_fast(uint16_t data);
/**
* @brief Reverse bits in uint8_t, faster than generic bit_lib_reverse_bits.
*
* @param byte Byte
* @return uint8_t the reversed byte
*/
uint8_t bit_lib_reverse_8_fast(uint8_t byte);
/**
* @brief Slow, but generic CRC8 implementation
*
* @param data
* @param data_size
* @param polynom CRC polynom
* @param init init value
* @param ref_in true if the right bit is older
* @param ref_out true to reverse output
* @param xor_out xor output with this value
* @return uint8_t
*/
uint16_t bit_lib_crc8(
uint8_t const* data,
size_t data_size,
uint8_t polynom,
uint8_t init,
bool ref_in,
bool ref_out,
uint8_t xor_out);
/**
* @brief Slow, but generic CRC16 implementation
*
* @param data
* @param data_size
* @param polynom CRC polynom
* @param init init value
* @param ref_in true if the right bit is older
* @param ref_out true to reverse output
* @param xor_out xor output with this value
* @return uint16_t
*/
uint16_t bit_lib_crc16(
uint8_t const* data,
size_t data_size,
uint16_t polynom,
uint16_t init,
bool ref_in,
bool ref_out,
uint16_t xor_out);
/**
* @brief Convert number to bytes in big endian order
*
* @param src number to convert
* @param len max used bytes count
* @param dest destination
* @return void
*/
void bit_lib_num_to_bytes_be(uint64_t src, uint8_t len, uint8_t* dest);
/**
* @brief Convert number to bytes in little endian order
*
* @param src number to convert
* @param len max used bytes count
* @param dest destination
* @return void
*/
void bit_lib_num_to_bytes_le(uint64_t src, uint8_t len, uint8_t* dest);
/**
* @brief Convert bytes to number in big endian order
*
* @param src byte array
* @param len max used bytes count
* @return uint64_t
*/
uint64_t bit_lib_bytes_to_num_be(const uint8_t* src, uint8_t len);
/**
* @brief Convert bytes to number in little endian order
*
* @param src byte array
* @param len max used bytes count
* @return uint64_t
*/
uint64_t bit_lib_bytes_to_num_le(const uint8_t* src, uint8_t len);
/**
* @brief Convert bytes in binary-coded decimal encoding to number
*
* @param src byte array
* @param len max used bytes count
* @param is_bcd will be true if all processed bytes is BCD encoded (no A-F nibbles)
* @return uint64_t
*/
uint64_t bit_lib_bytes_to_num_bcd(const uint8_t* src, uint8_t len, bool* is_bcd);
#ifdef __cplusplus
}
#endif