as.binary {rdiversity}R Documentation

as binary digit.

Description

Converts an integer (Base10) to a binary (Base2) number. It also converts a logical vector to a binary (Base2) number (see examples).

Usage

as.binary(x, signed=FALSE, littleEndian=FALSE, size=2, n=0, logic=FALSE)

Arguments

x

integer or logical vector.

signed

TRUE or FALSE. Unsigned by default. (two's complement)

littleEndian

if TRUE. Big Endian if FALSE.

size

in Byte. Needed if signed is set. (by default 2 Byte)

n

in Bit. Can be set if unsigned is set to TRUE. (by default 0 Bit = auto)

logic

If set to TRUE, x is expected as logical vector.

Details

The binary number is represented by a logical vector. The bit order usually follows the same endianess as the byte order. No floating-point support. If logic is set to TRUE an integer vector is intepreted as a logical vector (>0 becomes TRUE and 0 becomes FALSE)

Auto switch to signed if num < 0.

Value

a vector of class binary.

See Also

is.binary and binary

Examples

as.binary(0xAF)
as.binary(42)
as.binary(42, littleEndian=TRUE)
as.binary(c(0xAF, 0xBF, 0xFF))
as.binary(c(2,4,8,16,32), signed=TRUE, size=1)
as.binary(-1, signed=TRUE, size=1)
as.binary(1:7, n=3)
as.binary(sample(2^8,3),n=8)
as.binary(c(1,1,0), signed=TRUE, logic=TRUE)
as.binary(c(TRUE,TRUE,FALSE), logic=TRUE)

[Package rdiversity version 2.2.0 Index]