DEV Community

Discussion on: You're not worth hiring unless...

Collapse
 
e4emre profile image
Emre

That's just half a dozen lines of code at most. I never wrote decimal to binary converting algorithm before but I can fart one up in a few seconds, it's something like:

digitstring append character (number mod 2)
number = number divide by 2
if number >= 2 repeat else return digitstring

and the 2 can be replaced with any integer value to give the base-n expansion for any number for any base. If you have trouble figuring out how to generate the binary expansion of a number then don't worry, you're not alone: you're like 90% of coders and most hiring managers don't know the difference. Just memorize a bunch of random algorithms and hope that one of them turns out to be the one the interviewer asks you to regurgitate.