I need to perform bitwise operations on tibble columns containing strings of bits. For example, I would like to be able to do something like
ds <- tibble(Id=1:2, X1=c("001", "011"), X2=c("101", "110"))
mutate(ds, X1andX2 = magic.AND(X1,X2))
to obtain
# A tibble: 2 x 4
      Id    X1    X2   X1andX2
    <int> <chr> <chr>   <chr>
1     1    001   101     001
2     2    011   110     010
I am operating on the data sets that are not particularly large (~50k rows) but I have to perform this operation many times. So, I'm looking for something more or less efficient and simple.
Since I have to run many join and group operations, I would prefer an approach compatible with dplyr.
Edit: Sorry, the example above is not very good as three-bit strings produce results that look like three-bit strings after casting to integers and padding with 0s (see Sotos's answer that almost works). Also, it would be nice to see a solution for long strings, i.e. more than 32 bits. Here is a better example.
ds <- tibble(Id=1:2, X1=c("0101", "1110"), X2=c("1110", "0110"))
The output
# A tibble: 2 x 4
      Id    X1    X2   X1andX2
    <int> <chr> <chr>   <chr>
1     1    0101  1110    0100
2     2    1110  0110    0110