Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

mmmmm

Adding 1 without using =, -, *, /

This topic is 5166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how would you do this function. I know what to do if its even thats easy. unsigned int AddOne(unsigned int x) { ... } that returns x + 1. The function must not contain the following symbols: +,-,*,/ also Imagine you are doing integer arithmatic and multiplication is computationally expensive. What''s a really quick way to multiply by the number 7?

Share this post


Link to post
Share on other sites
Advertisement
If this is homework, it doesn''t belong on this board.

Otherwise, premature optimization is the root of all evil.

Share this post


Link to post
Share on other sites
These sound very much like homework problems, and the rules here say answers to homework problems may not be given. Though it is allowed to give hints when the person asking shows they are trying, you did not do so.

Share this post


Link to post
Share on other sites
That doesn''t just look like homework, that IS homework. Either that or interview questions. Either way, we can''t help you.

Share this post


Link to post
Share on other sites
I actually got the question, "how do you multiply by 7 without using the multiply operator?" during an interview at EA. The answer to that one was easy, it was the follow up, "divide a number by 7 without using the divide operator" that I couldn''t figure out. No wonder I screwed up the interview.

--Wendy

Share this post


Link to post
Share on other sites
Not homework. I have tried a couple of things. But none have seemed to work I dont use alot of bit operators. I know how they work but I cant seem to solve this one.

For even you just flip the first bit. Hmm im going to keep trying if I get it ill repost

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Where I could research this would help. I dont need the answer. I just dont know where to begin looking for help.

Share this post


Link to post
Share on other sites
I could have sworn I''ve seen the answer to both of these right here on GameDev. Tried a search, though, and it was futile.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
yea there are other bitwise posts with these types of questions. But not on this one.

Share this post


Link to post
Share on other sites
quote:
Original post by wendy
I actually got the question, "how do you multiply by 7 without using the multiply operator?" during an interview at EA. The answer to that one was easy, it was the follow up, "divide a number by 7 without using the divide operator" that I couldn''t figure out. No wonder I screwed up the interview.

--Wendy


Division by seven is just as easy, you just have to basically go the other way with it (well not exactly, but if you play with it, you''ll get it).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!