summaryrefslogtreecommitdiffstats
path: root/vendor/crypto-bigint/src/limb/bits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/crypto-bigint/src/limb/bits.rs')
-rw-r--r--vendor/crypto-bigint/src/limb/bits.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/vendor/crypto-bigint/src/limb/bits.rs b/vendor/crypto-bigint/src/limb/bits.rs
new file mode 100644
index 0000000..02a74de
--- /dev/null
+++ b/vendor/crypto-bigint/src/limb/bits.rs
@@ -0,0 +1,18 @@
+use super::Limb;
+
+impl Limb {
+ /// Calculate the number of bits needed to represent this number.
+ pub const fn bits(self) -> usize {
+ Limb::BITS - (self.0.leading_zeros() as usize)
+ }
+
+ /// Calculate the number of leading zeros in the binary representation of this number.
+ pub const fn leading_zeros(self) -> usize {
+ self.0.leading_zeros() as usize
+ }
+
+ /// Calculate the number of trailing zeros in the binary representation of this number.
+ pub const fn trailing_zeros(self) -> usize {
+ self.0.trailing_zeros() as usize
+ }
+}