#### Archived

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

# Adding 1 without using =, -, *, /

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

## 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 on other sites
If this is homework, it doesn''t belong on this board.

Otherwise, premature optimization is the root of all evil.

##### 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 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 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 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 on other sites
Where I could research this would help. I dont need the answer. I just dont know where to begin looking for help.

##### 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 on other sites
yea there are other bitwise posts with these types of questions. But not on this one.

##### 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).

1. 1
Rutin
64
2. 2
3. 3
4. 4
5. 5

• 16
• 10
• 29
• 20
• 9
• ### Forum Statistics

• Total Topics
633413
• Total Posts
3011759
• ### Who's Online (See full list)

There are no registered users currently online

×