r/csinterviewproblems • u/antonyashk • Aug 24 '20
How to add two numbers without using + operator?
https://medium.com/dev-genius/how-to-add-two-numbers-without-using-operator-356945cf8fa
2
Upvotes
7
u/thomascgalvin Aug 24 '20
I write Spring Boot apps all day. If some chucklefuck asked me to do this in an interview, I would walk out of the room.
Nothing against you, OP, but these kinds of interview questions are completely fucking broken.
5
u/mosquitobird11 Aug 24 '20
I'm going to go against the sentiment with this problem and say that for some positions this is actually an extremely valuable question.
This question is rare in being able to test if the candidate actually has a firm foundation in logical and low-level computing. The only way to reasonably add two numbers without the + operator would be to understand bitwise operators and how to manipulate bits to simulate an add.
So is this question useful to front end web devs? Not really. But it would be, in my opinion, extremely useful for interviewing someone for an embedded systems position, or device engineering, or even some web dev/full stack positions if you ever have to work at the byte level (I do at my current job for interfacing with smart home devices a lot).
The question is actually really simple if you understand logical operators and byte-level computing fundamentals.
2
u/AvidOxid Aug 24 '20
I thought I was being cheeky when I saw this question on leetcode and did:
But yeah, bitwise operations is the real answer. You can read through the discussions/solutions on leetcode for this question. They have some pretty nice/detailed answers.
0
u/[deleted] Aug 24 '20
[deleted] — view deleted comment