Link to home
Start Free TrialLog in
Avatar of ThePATMAN26
ThePATMAN26Flag for United States of America

asked on

Change Binary value by a value of 4 using binary or, shift or and functions

I'm using C++ to write a program for school. I'm having some trouble with working with binary values. The professor wants us to start with the value 0x7A060 and increment it by four using the binary and, or and shift functions. The final values should be:

7a060
7a064
7a068
7a06c

Any help anyone could provide would be much much much appreciated!
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PATMAN, thanks for being honest and saying you have a homework assignment.

jkr is correct that we shouldn't provide code.

However, we can look at code that you write and post.  You can also tell us what you are thinking to get guidance.  (Show us that you've attempted the homework and give us something to react to.)
Avatar of ThePATMAN26

ASKER

Evening,

Thanks to both of you. JKR's comments were just the amount of guidance I needed, I was able to draw up my own source code.

Would either of you have any recommendations on where would be a good place to find some supplemental guidance when it comes to working with assembly level stuff?

Thanks,
-Patrick
There's an assembly language section here at EE.   Progamming->Programming Languages->Assembly
Great, one last question. I have the stored value of eleven (1011) and I want to increment it by 1 using the OR function with value 0001. How would you recommend going about it (steps only, I can generate my own code).
Well, you know the result - it's 1100. So, only 'or' will not be sufficiant, you need to mask out the lower two bits with 'and' first, then you can use 'or' to set the 3rd.
Sounds to me like you should create a generic function.  Are you allowed to have a carry bit?

Just like grade school adding except in binary.  Start from the right.  XOR the current bit column to get the bit value in the sum row.  AND the bits to see if you should set the carry bit.  It gets a bit trickier in the 2nd column once the carry bit is on but I bet you can figure it out.

If you can write that, you can add any two integers and you'd be close to how hardware does this work.  (Except you are in serial and hardware does work in parallel.)