mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibCrypto: Add a method to count the number of digits in a big int
This commit is contained in:
Notes:
github-actions[bot]
2026-02-22 14:40:33 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/ecdaa7911f8 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8063
@@ -147,6 +147,20 @@ ErrorOr<String> UnsignedBigInteger::to_base(u16 N) const
|
||||
return StringView(buffer.bytes().slice(0, written - 1)).to_ascii_lowercase_string();
|
||||
}
|
||||
|
||||
size_t UnsignedBigInteger::count_digits_in_base(u16 base) const
|
||||
{
|
||||
VERIFY(base <= 36);
|
||||
|
||||
if (is_zero())
|
||||
return 1;
|
||||
|
||||
int size = 0;
|
||||
MP_MUST(mp_radix_size(&m_mp, base, &size));
|
||||
|
||||
// mp_radix_size includes a null byte.
|
||||
return static_cast<size_t>(size) - 1;
|
||||
}
|
||||
|
||||
u64 UnsignedBigInteger::to_u64() const
|
||||
{
|
||||
return mp_get_u64(&m_mp);
|
||||
|
||||
Reference in New Issue
Block a user