1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Bitwise Operations

  1. Apr 25, 2015 #1
    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. jcsd
  3. Apr 25, 2015 #2

    mfb

    User Avatar
    2016 Award

    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?
     
  4. Apr 25, 2015 #3
    If you don't get it, you should check this out: www.vipan.com/htdocs/bitwisehelp.html
     
    Last edited: Apr 25, 2015
  5. Apr 25, 2015 #4
    Can you do any of it?
     
  6. Apr 25, 2015 #5
    I cannot do anything and that website didn't help.
     
  7. Apr 25, 2015 #6
    No. :cry:
     
  8. Apr 25, 2015 #7

    Mark44

    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.
     
  9. Apr 25, 2015 #8
    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
  10. Apr 25, 2015 #9

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

    IS THIS RIGHT?
     
  11. Apr 25, 2015 #10

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    See if it works with other inputs as well, like 11110000 for both parts. If it does not, something is wrong.
     
  12. Apr 25, 2015 #11
    I'm pretty sure its right. Am I missing something?
     
  13. Apr 25, 2015 #12

    mfb

    User Avatar
    2016 Award

    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?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Bitwise Operations
  1. Operational Amplifiers (Replies: 7)

  2. Conditional Operators (Replies: 7)

Loading...