How do i prepare for that :\ ?
How do i prepare for that :\ ?
If I were put on the spot with those constraints I'd suggest a lookup table.
I'm currently looking for a new job, however I tend to ask about the process upfront, if it sounds like a wanky anal probe type of interview I simply withdraw from the process. Which is sad, as some of the jobs I'd really like.
The only way to "prepare" for situations like these is to go in with a willingness to trust one's own gut - and to simply break off the interview once you start to feel you're not being treated professionally, and that the questions you're being asked are, like the above, completely out of line.†
† Okay, maybe if you were applying for the job of chairing some IEEE committee on numerical standards or something, thiis particular question might be. But I somehow doubt that was the case with this particular role.
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.
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.
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.
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.