Byte swap question (Bitwise operation) [on hold] The Next CEO of Stack Overflowsystem call to peek next byte from serial portTest question regarding grep

INSERT to a table from a database to other (same SQL Server) using Dynamic SQL

Do I need to write [sic] when a number is less than 10 but isn't written out?

Does increasing your ability score affect your main stat?

Why isn't acceleration always zero whenever velocity is zero, such as the moment a ball bounces off a wall?

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

Is wanting to ask what to write an indication that you need to change your story?

Can a Bladesinger Wizard use Bladesong with a Hand Crossbow?

Find non-case sensitive string in a mixed list of elements?

Is micro rebar a better way to reinforce concrete than rebar?

Why doesn't UK go for the same deal Japan has with EU to resolve Brexit?

How do I align (1) and (2)?

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Is French Guiana a (hard) EU border?

Does Germany produce more waste than the US?

Is it professional to write unrelated content in an almost-empty email?

Are police here, aren't itthey?

Dominated convergence theorem - what sequence?

What does "Its cash flow is deeply negative" mean?

What steps are necessary to read a Modern SSD in Medieval Europe?

How to count occurrences of text in a file?

If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?

Solving system of ODEs with extra parameter

0 rank tensor vs 1D vector

Is it convenient to ask the journal's editor for two additional days to complete a review?



Byte swap question (Bitwise operation) [on hold]



The Next CEO of Stack Overflowsystem call to peek next byte from serial portTest question regarding grep










-1















I have seen some bitwise operation practice questions (in C language) and there was one I didn't understand: you had to swap the nth and the mth byte in a specifc integer "x" using only bitwise operations, and that n and m were both <=3. The solution involved masking the last 8 bits of the number resulting from xor based on x >> (n<<3) to x >> (m<<3), but the part I don't understand is why they shifted m/n right 3.










share|improve this question















put on hold as off-topic by ilkkachu, Rui F Ribeiro, muru, jimmij, maulinglawns yesterday



  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.




















    -1















    I have seen some bitwise operation practice questions (in C language) and there was one I didn't understand: you had to swap the nth and the mth byte in a specifc integer "x" using only bitwise operations, and that n and m were both <=3. The solution involved masking the last 8 bits of the number resulting from xor based on x >> (n<<3) to x >> (m<<3), but the part I don't understand is why they shifted m/n right 3.










    share|improve this question















    put on hold as off-topic by ilkkachu, Rui F Ribeiro, muru, jimmij, maulinglawns yesterday



    • This question does not appear to be about Unix or Linux within the scope defined in the help center.
    If this question can be reworded to fit the rules in the help center, please edit the question.


















      -1












      -1








      -1








      I have seen some bitwise operation practice questions (in C language) and there was one I didn't understand: you had to swap the nth and the mth byte in a specifc integer "x" using only bitwise operations, and that n and m were both <=3. The solution involved masking the last 8 bits of the number resulting from xor based on x >> (n<<3) to x >> (m<<3), but the part I don't understand is why they shifted m/n right 3.










      share|improve this question
















      I have seen some bitwise operation practice questions (in C language) and there was one I didn't understand: you had to swap the nth and the mth byte in a specifc integer "x" using only bitwise operations, and that n and m were both <=3. The solution involved masking the last 8 bits of the number resulting from xor based on x >> (n<<3) to x >> (m<<3), but the part I don't understand is why they shifted m/n right 3.







      c






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      Rui F Ribeiro

      41.8k1483142




      41.8k1483142










      asked 2 days ago









      Goodwin LuGoodwin Lu

      435




      435




      put on hold as off-topic by ilkkachu, Rui F Ribeiro, muru, jimmij, maulinglawns yesterday



      • This question does not appear to be about Unix or Linux within the scope defined in the help center.
      If this question can be reworded to fit the rules in the help center, please edit the question.







      put on hold as off-topic by ilkkachu, Rui F Ribeiro, muru, jimmij, maulinglawns yesterday



      • This question does not appear to be about Unix or Linux within the scope defined in the help center.
      If this question can be reworded to fit the rules in the help center, please edit the question.




















          1 Answer
          1






          active

          oldest

          votes


















          1














          Because if n is a position within the word, in bytes, then 8*n is the same position in bits. And n<<3 is the same as 8*n (23 = 8).



          With n=1, n<<3 is 8, and (x >> (n << 3)) & 0xff would move the second lowest byte to the bottom position, and mask the rest of the word out. (The bytes would numbered starting from zero, of course.)



          (I'm assuming bytes of 8 bits, since I think that's by far the most common case at least nowadays.)






          share|improve this answer





























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Because if n is a position within the word, in bytes, then 8*n is the same position in bits. And n<<3 is the same as 8*n (23 = 8).



            With n=1, n<<3 is 8, and (x >> (n << 3)) & 0xff would move the second lowest byte to the bottom position, and mask the rest of the word out. (The bytes would numbered starting from zero, of course.)



            (I'm assuming bytes of 8 bits, since I think that's by far the most common case at least nowadays.)






            share|improve this answer



























              1














              Because if n is a position within the word, in bytes, then 8*n is the same position in bits. And n<<3 is the same as 8*n (23 = 8).



              With n=1, n<<3 is 8, and (x >> (n << 3)) & 0xff would move the second lowest byte to the bottom position, and mask the rest of the word out. (The bytes would numbered starting from zero, of course.)



              (I'm assuming bytes of 8 bits, since I think that's by far the most common case at least nowadays.)






              share|improve this answer

























                1












                1








                1







                Because if n is a position within the word, in bytes, then 8*n is the same position in bits. And n<<3 is the same as 8*n (23 = 8).



                With n=1, n<<3 is 8, and (x >> (n << 3)) & 0xff would move the second lowest byte to the bottom position, and mask the rest of the word out. (The bytes would numbered starting from zero, of course.)



                (I'm assuming bytes of 8 bits, since I think that's by far the most common case at least nowadays.)






                share|improve this answer













                Because if n is a position within the word, in bytes, then 8*n is the same position in bits. And n<<3 is the same as 8*n (23 = 8).



                With n=1, n<<3 is 8, and (x >> (n << 3)) & 0xff would move the second lowest byte to the bottom position, and mask the rest of the word out. (The bytes would numbered starting from zero, of course.)



                (I'm assuming bytes of 8 bits, since I think that's by far the most common case at least nowadays.)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 days ago









                ilkkachuilkkachu

                62.8k10103180




                62.8k10103180













                    Popular posts from this blog

                    getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                    Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                    Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.