binstr: Convert integer to binary string

Description Usage Arguments Value Author(s) Examples

View source: R/binary-strings.R

Description

Description needed

Usage

1
binstr(i, maxBits = NA)

Arguments

i

Positive integer <= 2^53 (<= 9.007199e+15).

maxBits

Maximum number of bits to print (default NA).

Value

Character vector.

Author(s)

Alex Chubaty

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
x <- sample(0:9999, 10000)
y <- binstr(x) # length is 14 bits

## Not run: 
# alternate (but slower) conversion to binary string
R.utils::intToBin(x)

## End(Not run)

# convert binary string to integer value (very fast)
strtoi(y, base = 2)
strtoi(substr(y, 1, 4), base = 2)
strtoi(substr(y, 5, 8), base = 2)
strtoi(substr(y, 9, 11), base = 2)
strtoi(substr(y, 12, 14), base = 2)

# see also `binary()` and `unbinary()` in the `composition` package (requires x11)

achubaty/amc documentation built on April 6, 2021, 6:56 a.m.