Hacker News new | ask | show | jobs
by usingpond 4565 days ago
Similar in NYC. I remember an interview where I was asked to bit-shift in Javascript, for the sake of itself.

I've also had good experiences though--I liked one where I had to build certain UI components and get my code evaluated in real-time.

1 comments

Since it's just *2 (right shift) or /2 (left shift), I'm pretty sure they wanted to quickly test how are you with general programming knowledge.
In javascript, the number type is just number. To truly bit shift with this method, you'd need to convert the bitwise representation into a number, perform the given operation, handle the corner case of odd numbers when dividing, and the convert it back into some representation of bits.

Trying to judge people with questions like this seems like a misguided endeavor. Yes, it's probably valuable to know that bitshifting is roughly equivalent to *2 and /2. But that's more like trivia - the chances you'll actually use that in real life is really low. I've had to work with people that think bitshifting is an appropriate optimization for division/multiplication by even numbers. I then have to explain overflows, underflows, and the fact that the compiler will compile it to shifts if appropriate anyway, so don't sacrifice readability in the name of micro-optimization.