Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Good article, but this interview question is not good.

> How to swap two numbers without using a temporary variable?

I know interviewers expect XOR, but PCs have XCHG instruction.

It’s the same error when they asking to compute number of set bits, expecting “lookup table”. Same error when they ask to find the least/most significant set bit index, expecting some bit tricks. Processors have dedicated instructions to do these things, typically faster than smart-ass manual versions.

Moreover, for simple things like XCHG, BT, BTC, BSWAP compilers are aware and normally produce them from normally-looking i.e. readable code.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: