utils {boolfun}R Documentation

Some Auxiliary Functions

Description

Some functions used by the package and that might be useful for other purposes.

Usage

toBin(a,n)
toInt(v)
weight(x)
strip(string,chars)

Arguments

a an integer.
n an integer.
v a vector of integers in {0,1}.
x an integer or a vector of integers. If x is a vector the function will be applied to each of its components.
string a string (e.g. "hello")
chars a vector of characters (e.g. c("h","e","l","l","o"))

Value

toBin returns a binary representation of x as a vector of n integers. Note that the binary representation is reversed, that is, toBin(8,4) returns (0,0,0,1) instead of (1,0,0,0).
toInt returns the integer encoded in binary vector v.
weight returns the hamming weight of the binary representation of x. If x is a vector, the hamming weight of each of its components is returned in a vector.
strip returns the input argument string stripped from the input characters chars. For example, strip( "hello", c("o","e") ) returns "hll".

Author(s)

F.Lafitte

See Also

BooleanFunction, Polynomial , Assignment

Examples

    powers <- c( 2, 4, 8, 16, 32,  64 )
    if( any( weight(powers) != 1 ) )
        stop("This message should not print")
    for( i in 0:(2^10 -1) )
        if( sum(toBin(i,10)) != weight(i) )
            stop("This message should not print")

[Package boolfun version 0.2.6 Index]