Encode or decode an ip_address as a binary bit string.
Arguments
- x
ip_to_binary(): Anip_addressvectorbinary_to_ip(): A character vector containing only0and1characters
Value
ip_to_binary(): A character vectorbinary_to_ip(): Anip_addressvector
Details
The bits are stored in network order (also known as big-endian order), which is part of the IP standard.
IPv4 addresses use 32 bits, IPv6 addresses use 128 bits, and missing values
are encoded as NA.
See also
Other address representations:
ip_to_bytes(),
ip_to_hex(),
ip_to_integer()
Examples
x <- ip_address(c("192.168.0.1", "2001:db8::8a2e:370:7334", NA))
ip_to_binary(x)
#> [1] "11000000101010000000000000000001"
#> [2] "00100000000000010000110110111000000000000000000000000000000000000000000000000000100010100010111000000011011100000111001100110100"
#> [3] NA
binary_to_ip(ip_to_binary(x))
#> <ip_address[3]>
#> [1] 192.168.0.1 2001:db8::8a2e:370:7334 <NA>