diff --git a/src/ipv4.rs b/src/ipv4.rs index d162fb6..00e7b14 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -215,9 +215,8 @@ impl Ipv4Network { /// assert_eq!(tinynet.size(), 1); /// ``` pub fn size(self) -> u32 { - let host_bits = u32::from(IPV4_BITS - self.prefix); - (2 as u32).pow(host_bits) - } + 1 << (u32::from(IPV4_BITS - self.prefix)) + } /// Returns the `n`:th address within this network. /// The adresses are indexed from 0 and `n` must be smaller than the size of the network. diff --git a/src/ipv6.rs b/src/ipv6.rs index 756c3a9..865d0ac 100644 --- a/src/ipv6.rs +++ b/src/ipv6.rs @@ -242,7 +242,7 @@ impl Ipv6Network { /// ``` pub fn size(&self) -> u128 { let host_bits = u32::from(IPV6_BITS - self.prefix); - (2 as u128).pow(host_bits) + 2u128.pow(host_bits) } }