Hacker News new | ask | show | jobs
by mpeg 3146 days ago
IMHO if it's for a senior engineer position, you should at least be able to explain how that would be implemented (bitwise operations) even if you wouldn't get it right in a whiteboard.
3 comments

Could you explain it to us? Thx.

I know how bitwise operators works and have a CS degree... But even with googling I couldn't find a straight forward way to implement a general exponential operator using only bit operations.

You need some cleverness to code an add(x, y) method with only bitwise operators.

Then, you need to code a multiply(x, y) method using some more bit shifting cleverness and your new add method.

Then, do repeated squaring using your new multiply method.

Sure, but that's not a very satisfying answer because it doesn't rely on any special insight about how exponention works. It would be better to just ask someone to code up addition and/or multiplication using bitwise operations if that's what you want to test. That's sort of a reasonable question in the case of addition. Asking someone to implement multiplication using bitwise operations in a phone interview would be pretty crazy, though.
Depends on the job.

Aside from having to port an algorithm, I'm pretty sure the last time I used a bitwise operator seriously in 10 years was back in uni.

You're not talking about an engineering problem, first of all (assuming it's a software implementation being talked about, of course). Secondly, it's difficult for me to see how this particular problem is a good motivation for discussion about the use of bitwise operations in general. I've written code in low level game engines, real time computational systems, physics and for drivers. The first and last items are the only ones where bitwise operations of this sort were even necessary to consider.

Unless this problem is for a job working on calculations on hardware that only supplies bitwise ops, it's a math trivia problem disguised as a coding interview question.