Learn R Programming

ipaddress (version 0.2.0)

binary: Represent address as binary

Description

as_binary() and from_binary() encode and decode an ip_address vector to a character vector of bits.

Usage

as_binary(ip)

from_binary(bits)

Arguments

ip

An ip_address vector

bits

A character vector containing only 0 and 1 characters

Value

  • as_binary() returns a character vector

  • from_binary() returns an ip_address vector

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

Use as_packed() and from_packed() to encode/decode raw bytes.

Examples

Run this code
# NOT RUN {
x <- ip_address(c("192.168.0.1", "2001:db8::8a2e:370:7334", NA))
as_binary(x)

from_binary(as_binary(x))
# }

Run the code above in your browser using DataLab