to.binary: Binary representation of non-negative integer

Description Usage Arguments Value Author(s) Examples

View source: R/to.binary.R

Description

A non-negative integer is represented as a binary number. The digits, 0 or 1, of this number are returned in a vector.

Usage

1
to.binary(n, k = ceiling(logb(n+1,base=2)))

Arguments

n

a non-negative integers

k

number of digits to be returned.

Value

A vector of length k. The first element is the least significant digit.

Author(s)

A.I. McLeod

Examples

1
2
3
4
5
to.binary(63)
to.binary(64)
#sometimes we want to pad result with 'leading' 0's
to.binary(63, k=20)
to.binary(64, k=20)

Example output

Loading required package: leaps
[1] 1 1 1 1 1 1
[1] 0 0 0 0 0 0 1
 [1] 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [1] 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0

bestglm documentation built on March 26, 2020, 7:25 p.m.