CidrNumber
Number with a byte layout and semantics optimized for CIDR/IP operations. The maximum number of addresses inside an IP address space is 2^32 for IPv4 and 2^128 for IPv6. Hence, 32/128-bit unsigned integers are not enough to represent the size of /0 networks, and an additional bit is needed. At the same time, the actual number of bytes used for addresses and netmasks is 4/16, which is why (by default) a CidrNumber's byte representation is truncated to 4/16 bytes to keep it efficient for CIDR operations.
Ranges:
IPv4 (CidrNumber.V4): valid values are in 0, 2^32. Creating a CidrNumber.V4 from an ULong truncates it to the modeled IPv4 width (2^32). It does not signal overflow
IPv6 (CidrNumber.V6): valid values are in 0, 2^128.
Overflow/underflow semantics:
Arithmetic operations (+ and -) return null on overflow/underflow, ensuring values stay within the valid ranges above.
Bitwise operations (and, or, xor), shifts (shl, shr), and inversion (inv) operate within the modeled bit-width and always yield a representable value in the respective range.
Its String representation is the hex-encoded byte-representation of the number produced by toByteArray(truncate = false)
. I.e., 5 bytes for IPv4 when equal to 2^32 and 17 bytes for IPv6 when equal to 2^128; otherwise 4/16 bytes.
See also
Inheritors
Functions
Converts the internal representation of the object into a ByteArray optimized for CIDR/IP operations. The maximum number of addresses inside an IP address space is 2^32 for IPv4 and 2^128 for IPv6. Hence, 32/128-bit numbers are not enough to represent the size of /0 networks, and an additional bit is needed.