R/bin2dec.R

#' conversion between decimal and binary
#'
#' \code{bin2dec(x)} converts binary to decimal
#'
#' @param x is a number

bin2dec <- function(x){
  x <- as.character(x)
  b <- as.numeric(unlist(strsplit(x, "")))
  pow <- 2 ^ ((length(b) - 1):0)
  sum(pow[b == 1])
}
helophilus/ColsTools documentation built on May 30, 2019, 4:03 p.m.