3 ms·
This is making me crazy, does someone have the solution? The best I could come up with is: function one_bit(x) { return 1 >>> (x & (x + ~0)) } ("x + ~0" is
by norswap 13y ago
This is making me crazy, does someone have the solution?
The best I could come up with is:
function one_bit(x) {
return 1 >>> (x & (x + ~0))
}
("x + ~0" is equivalent to "x - 1")
But this doesn't work when x is 0 All other case should be fine, afaik.
- ejk314 13y agoThat would work if the `>>>` operator worked as expected, but actually it just looks at the first 5 bits of the second variable so that `a>>>b` is effectively equivalent to `a>>>(b&31)`. His description of it is wrong. http://jsfiddle.net/Ayzkt/2/ http://jsfiddle.net/Ayzkt/2/