jim holtman wrote:
try this:
b <- c(1, 0, 1, 0, 1, 0, 1, 0, 1, 0)
p <- c(1, 3, 5, 7)
b[p] <- ifelse(b[p] == 0, 1, 0)
I'll have to look up the ifelse operator, looks like
the ternary operator used in C
b[p] = b[p]==0?1:0
Cool - thanks!
Esmail
__
David Winsemius wrote:
I do not think your wetware processed the inputs correctly. The second
bit should not have been flipped:
Ooops .. yes you are right!
Try this loop free index based solution:
b <- c( 1, 0, 1, 0, 1, 0, 1, 0, 1, 0)
r <- b
r[p] <- 0 + !r[p] # adding 0 converts logical
try this:
> b <- c(1, 0, 1, 0, 1, 0, 1, 0, 1, 0)
> p <- c(1, 3, 5, 7)
> b[p] <- ifelse(b[p] == 0, 1, 0)
> b
[1] 0 0 0 0 0 0 0 0 1 0
On Sun, Apr 19, 2009 at 3:24 PM, Esmail wrote:
> I have a string of binary values, and I would like to flip certain
> bits in a set of positions.
>
> Let's say th
I do not think your wetware processed the inputs correctly. The second
bit should not have been flipped:
Try this loop free index based solution:
b <- c( 1, 0, 1, 0, 1, 0, 1, 0, 1, 0)
r <- b
r[p] <- 0 + !r[p] # adding 0 converts logical TRUE/FALSE to 0/1
r
[1] 0 0 0 0 0 0 0 0 1 0
The "
I have a string of binary values, and I would like to flip certain
bits in a set of positions.
Let's say the
vector p contains position [1, 3, 5, 7]
vector b contains bits [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]
result r should be [0, 1, 0, 0, 0, 0, 0, 0, 1, 0]
in pseudo code this would be somet
5 matches
Mail list logo