R/IntDecToBin.R

Defines functions IntDecToBin

Documented in IntDecToBin

IntDecToBin <- function(x, m = 31) {
  # Find binary expansion of positive integer x
     if (!is.integer(x) | any(x < 0)) warning("Nonnegative integers required.  Results may be unreliable.\n")
     n <- length(x)
     b <- matrix(0, nrow = n, ncol = m)
     for (i in 1:m) {
         b[, i] <- (x%%2L)!=0L   
         x <- x%/%2L
     }
     return(b)
}

Try the MiscMath package in your browser

Any scripts or data that you put into this service are public.

MiscMath documentation built on April 13, 2025, 9:07 a.m.