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

1 |

`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 |

`n` |
in Bit. Can be set if |

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

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)

Little Endian (LSB) —> (MSB)

Big Endian (MSB) <— (LSB)

Auto switch to signed if num < 0.

a vector of class binary.

is.binary and binary

1 2 3 4 5 6 7 8 9 10 | ```
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)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

All documentation is copyright its authors; we didn't write any of that.