mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 18:42:28 +00:00
feat(big): add HighBitPos
This commit is contained in:
parent
e9d3284c70
commit
6e62f0a604
3 changed files with 92 additions and 0 deletions
|
|
@ -68,6 +68,33 @@ void FromUnsigned(BigBuffer& buffer, uint32_t value) {
|
|||
buffer.SetCount(1);
|
||||
}
|
||||
|
||||
uint32_t HighBitPos(const BigBuffer& buffer) {
|
||||
uint32_t index = buffer.Count();
|
||||
if (index == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (buffer[--index] == 0) {
|
||||
if (index == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t mask = 0x80000000;
|
||||
uint32_t bitIndex = 32;
|
||||
while (bitIndex > 0) {
|
||||
bitIndex--;
|
||||
|
||||
if (buffer[index] & mask) {
|
||||
return (index * 32) + bitIndex;
|
||||
}
|
||||
|
||||
mask >>= 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t MakeLarge(uint32_t low, uint32_t high) {
|
||||
return low + (static_cast<uint64_t>(high) << 32);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ void FromBinary(BigBuffer& buffer, const void* value, uint32_t bytes);
|
|||
|
||||
void FromUnsigned(BigBuffer& buffer, uint32_t value);
|
||||
|
||||
uint32_t HighBitPos(const BigBuffer& a);
|
||||
|
||||
uint64_t MakeLarge(uint32_t low, uint32_t high);
|
||||
|
||||
void Mul(BigBuffer& a, const BigBuffer& b, uint64_t c);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue