, IPV4- 32- , 8 .
, "a.b.c.d", ,
(a<<24) + (b<<16) + (c<<8) + d
< . , a<<b a*2^b
CIDR , ( 32) . . 10.10.10.1/28 28- 32-28 = 4- . , ip (= 0x0A0A0A01) & 0xFFFFFFFF < 4 (= 0xFFFFFFF0), 0x0A0A0A00. ip :
sprintf("%d.%d.%d.%d", (n>>24)&0xff, (n>>16)&0xff, (n>>8)&0xff, n&0xff)
10.10.10.0. , 0xFFFFFFF0 ip , 255.255.255.248, , 28.
IPv6 , , 128 8 16- , , 0 (::)..
.
fe80::52e5:49ff:ffc9:1889/64 ==
;;convert the mask
0xffffffffffffffffffffffffffffffff << (128-64) =
0xffffffffffffffff0000000000000000
;;convert the ip:
fe80::52e5:49ff:ffc9:1889 ==
fe80:0000:0000:0000:52e5:49ff:ffc9:1889 ==
0xfe8000000000000052e549ffffc91889
0xfe8000000000000052e549ffffc91889
& 0xffffffffffffffff0000000000000000
= 0xfe800000000000000000000000000000
;;convert first address in range back to string:
fe80:0000:0000:0000:0000:0000:0000:0000 =
fe80::
, , , .