View source: R/binary-strings.R
binstr | R Documentation |
Convert integer to binary string
binstr(i, maxBits = NA)
i |
Positive integer <= 2^53 (<= 9.007199e+15). |
maxBits |
Maximum number of bits to print (default |
Character vector.
Alex Chubaty
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.