Translated dec2bitv() (#3)
This commit is contained in:
parent
ce53f1f45d
commit
98cde6b23e
2 changed files with 17 additions and 1 deletions
16
R/dec2bitv.R
Normal file
16
R/dec2bitv.R
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
dec2bitv <- function(d, n) {
|
||||||
|
# DEC2BITV Convert a decimal integer to a bit vector.
|
||||||
|
# bits <- dec2bitv(d, n) is just like the built - in dec2bin, except the answer is a vector, not a as.character.
|
||||||
|
# n is an optional minimum length on the bit vector.
|
||||||
|
# If d is a vector, each row of the output array will be a bit vector.
|
||||||
|
|
||||||
|
if (nargin() < 2) {
|
||||||
|
n <- 1 # Need at least one digit even for 0.
|
||||||
|
}
|
||||||
|
d <- d[]
|
||||||
|
|
||||||
|
f <- e <- NA
|
||||||
|
c(f, e) <- log2(max(d)) # How many digits do we need to represent the numbers?
|
||||||
|
bits <- floor(d * 2 ^ (seq(1 - max(n, e), 0))) %% 2
|
||||||
|
return(bits)
|
||||||
|
}
|
||||||
|
|
@ -10,5 +10,5 @@
|
||||||
#' size sortrows squeeze strcmp times zeros disp
|
#' size sortrows squeeze strcmp times zeros disp
|
||||||
#' @importFrom stats runif
|
#' @importFrom stats runif
|
||||||
#' @importFrom zeallot %<-%
|
#' @importFrom zeallot %<-%
|
||||||
#' @importFrom matlab2r nargin
|
#' @importFrom matlab2r nargin log2
|
||||||
NULL
|
NULL
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue