# Bitwise Operations

1. Apr 25, 2015

### gEOdude

1. The problem statement, all variables and given/known data
Given an 8-bit binary number “1001 1101”:
1)Turn off the 2 bits (masking bits to 0) on each side, and leave the middle 4 alone. The output should be “0001 1100”.

Given an 8-bit binary number “1001 1101”:
2) Toggle the values of the middle 4 bits (the opposite of what it currently is), and leave the 2 bits on each side untouched. The output should be “1010 0001”.

2. Relevant equations
None

3. The attempt at a solution
Its to confusing. I just want some help on how to do it. I understand the basics that To reset (i.e.make 0) a bit in a byte , I have to AND it with a mask of all 1’s except the bit to reset! AND ALSO the toggle (i.e. change from 0 to 1, or 1 to 0).
But no matter what input I add I cannot get the right output. Might as well be guessing.

Mod note: Changed "Giving" in the two problems to "Given".

Last edited by a moderator: Apr 25, 2015
2. Apr 25, 2015

### Staff: Mentor

What did you try so far?
Could you solve some part of the problem, e. g. masking or swapping only a single bit?

3. Apr 25, 2015

### DeathDealer

If you don't get it, you should check this out: www.vipan.com/htdocs/bitwisehelp.html

Last edited: Apr 25, 2015
4. Apr 25, 2015

### DeathDealer

Can you do any of it?

5. Apr 25, 2015

### gEOdude

I cannot do anything and that website didn't help.

6. Apr 25, 2015

### gEOdude

No.

7. Apr 25, 2015

### Staff: Mentor

Per the rules of this forum (https://www.physicsforums.com/threads/physics-forums-global-guidelines.414380/), we can't help you if you don't at least make an effort.

8. Apr 25, 2015

### DeathDealer

You should see what operator is needed first and the rest is easy. I'll make it as easy as possible.

(1001 1101) (operator) (8 digit number made up of 1s and 0s) = 0001 1100
(1001 1101) (operator) (8 digit number made up of 1s and 0s) = 1010 0001

Last edited: Apr 25, 2015
9. Apr 25, 2015

### gEOdude

(1001 1101) & (0101 1110) = 0001 1100
(1001 1101) ^ (0111 1110) = 1010 0001

IS THIS RIGHT?

10. Apr 25, 2015

### Staff: Mentor

See if it works with other inputs as well, like 11110000 for both parts. If it does not, something is wrong.

11. Apr 25, 2015

### gEOdude

I'm pretty sure its right. Am I missing something?

12. Apr 25, 2015

### Staff: Mentor

What is (1111 0000) & (0101 1110) and does it match (0011 000)?
What is (1111 0000) ^ (0111 1110) and does it match (1100 1100)?

Also, just a logical consideration: the outer 4 bits are always supposed to get the same effect (set to 0 in the first case, keep the same in the second case). Can something like (0101 1110) make sense, where different bits in this group are treated differently?