mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 10:32:29 +00:00
feat(big): add SBigBitLen
This commit is contained in:
parent
5edf49dae7
commit
24c6a5134c
3 changed files with 87 additions and 0 deletions
|
|
@ -7,6 +7,23 @@ void SBigAdd(BigData* a, BigData* b, BigData* c) {
|
|||
Add(a->Primary(), b->Primary(), c->Primary());
|
||||
}
|
||||
|
||||
void SBigBitLen(BigData* num, uint32_t* len) {
|
||||
auto& buffer = num->Primary();
|
||||
buffer.Trim();
|
||||
|
||||
auto index = buffer.Count() - 1;
|
||||
auto high = buffer[index];
|
||||
|
||||
uint32_t bitIndex;
|
||||
for (bitIndex = 31; bitIndex > 0; bitIndex--) {
|
||||
if (((1 << bitIndex) & high)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*len = (index * 32) + bitIndex + 1;
|
||||
}
|
||||
|
||||
int32_t SBigCompare(BigData* a, BigData* b) {
|
||||
return Compare(a->Primary(), b->Primary());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
void SBigAdd(BigData* a, BigData* b, BigData* c);
|
||||
|
||||
void SBigBitLen(BigData* num, uint32_t* len);
|
||||
|
||||
int32_t SBigCompare(BigData* a, BigData* b);
|
||||
|
||||
void SBigDel(BigData* num);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue