R/b2d.R

Defines functions b2d

Documented in b2d

###-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
### converting binary numbers to decimal with C code
###-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

b2d <- function(bin)
{
    if(!is.numeric(bin))
	stop("'bin' must be of mode numeric, got", mode(bin))
    if(!is.vector(bin))
	stop("'bin' must be a vector, got", class(bin))
    if( !all(bin %in% c(0,1)) )
	stop("'bin' must contain only 0s and 1s")
    # call C code
    rval <- .C( "bin2dec",
	binary=as.integer(bin),
	decimal=as.integer(0),
	len=as.integer(length(bin)) )
    return(rval$decimal)
}

Try the rgraph6 package in your browser

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

rgraph6 documentation built on May 2, 2019, 4:50 p.m.