[R] bit set or bit test

Jerome Asselin jerome at hivnet.ubc.ca
Thu Apr 17 19:11:54 CEST 2003


Hi Mike,

I'm not sure I understand your message, but see if this example is useful.

ntharray <- rbind(c(1,0,0,1,0),c(0,0,1,0,1))
ntharray%*%2^(0:(ncol(ntharray)-1))
#     [,1]
#[1,]    9
#[2,]   20

See also ?binary in package "wle".
library(wle)
binary(9,dim=5)
#$binary
#[1] 1 0 0 1 0
#
#$dicotomy
#[1]  TRUE FALSE FALSE  TRUE FALSE

HTH,
Jerome

On April 16, 2003 11:45 pm, Mike Sumner wrote:
> Hello, does R have functions for setting and testing
> bit values?
>
> I want to conserve memory for storing presence/absence
> data for large multiple arrays within a single array,
> using element values like
>
> present[x,y] <- ntharray[x,y]*(2^n)
>
> where presence is 1, non-presence is 0 and n is the
> nth array
>
> e.g.  1*(2^0) + 0*(2^1) + 0*(2^2) + 1*(2^3) + 0(2^4)
>
> for storing the value 9 for presence in the first and
> fourth array, and absence in the second, third and
> fifth arrays.
>
> Does R already have something to handle stuff like
> this?
>
> Cheers, Mike.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

-- 

Jerome Asselin (Jérôme), Statistical Analyst
British Columbia Centre for Excellence in HIV/AIDS
St. Paul's Hospital, 608 - 1081 Burrard Street
Vancouver, British Columbia, CANADA V6Z 1Y6
Email: jerome at hivnet.ubc.ca
Phone: 604 806-9112   Fax: 604 806-9044



More information about the R-help mailing list