R/bin2int.R

Defines functions bin2int

Documented in bin2int

##' Convert binary mode to integers.
##' 
##' @title Convert binary mode to integers.
##' @param bin string vector in binary mode.
##' @return A numeric vector.
##' @author Jian Li <\email{rinds.book@@gmail.com}>
##' @keywords string
##' @examples \dontrun{
##' bin2int("001101")
##' }
##'

bin2int <- function(bin) 
{
	res <- strsplit(bin, split = "")
	return(sapply(res, FUN = function(X) sum(as.numeric(X)*2^rev(seq_along(X))))/2)
}

Try the dsinr package in your browser

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

dsinr documentation built on May 2, 2019, 5:47 p.m.