1. HBit增加可对比和赋值功能
This commit is contained in:
parent
46601f7f8a
commit
5b1067f8d1
@ -83,5 +83,13 @@ HBitType HBitAll(const HBitType *data);
|
||||
// 如果所有比特为0, 返回1, 否则返回0
|
||||
HBitType HBitNone(const HBitType *data);
|
||||
|
||||
// 获取比特长度
|
||||
HBitLenType HBitGetLen(const HBitType *data);
|
||||
|
||||
// 复制比特, 需要两者长度一致, 否则返回0
|
||||
uint8_t HBitMemcpy(const HBitType *dst, HBitType *src);
|
||||
|
||||
// 比较两个比特是否相等, 需要两者长度一致, 相同返回1, 否则返回0
|
||||
uint8_t HBitEqual(const HBitType *a, const HBitType *b);
|
||||
|
||||
#endif //__H_BIT__
|
||||
|
||||
34
src/HBit.c
34
src/HBit.c
@ -1,6 +1,7 @@
|
||||
|
||||
|
||||
#include <HBit.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef LogD
|
||||
#define LogD(...)
|
||||
@ -113,3 +114,36 @@ HBitType HBitAll(const HBitType *data) {
|
||||
HBitType HBitNone(const HBitType *data) {
|
||||
return !HBitAny(data);
|
||||
}
|
||||
|
||||
HBitLenType HBitGetLen(const HBitType *data) {
|
||||
return GetBitLen(data);
|
||||
}
|
||||
|
||||
uint8_t HBitMemcpy(const HBitType *dst, HBitType *src) {
|
||||
if (!src || !dst) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (GetBitLen(src) != GetBitLen(dst)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_HBitBase *srcBase = (_HBitBase *)src;
|
||||
_HBitBase *dstBase = (_HBitBase *)dst;
|
||||
memcpy(dstBase->data, srcBase->data, _HBIT_BYTE_INDEX(srcBase->len) + 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t HBitEqual(const HBitType *a, const HBitType *b) {
|
||||
if (!a || !b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (GetBitLen(a) != GetBitLen(b)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_HBitBase *aBase = (_HBitBase *)a;
|
||||
_HBitBase *bBase = (_HBitBase *)b;
|
||||
return memcmp(aBase->data, bBase->data, _HBIT_BYTE_INDEX(aBase->len) + 1) == 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user