Search
 
SCRIPT & CODE EXAMPLE
 

C

switch every right 4 bit with the left 4 bits

//  Question 4
unsigned int switch_pairs(unsigned int n) {
    unsigned int threes = 0x33333333 ; // unsigned int 32 bits = 4 bytes
    unsigned int twelves = 0xCCCCCCCC ; // unsigned int 32 bits = 4 bytes

    // step one

    /*
       10111001
          &
       00110011 = 0x33

                */
    unsigned int res1 = n&threes;

    // make the every two pairs from right shift to left
    res1 <<=2;

    // step two
    /*
    10111001
       &
    11001100 = 0xCC
             */

    // make every pairs from lift shift to right
    unsigned  int res2 = n&twelves;
    res2 >>=2;

    // step three;
    return res1 | res2;

}
Comment

PREVIOUS NEXT
Code Example
C :: reverse binary tree c 
C :: gnuplot rectangle border color 
C :: how to initiate pointer array with null in c 
C :: 50 north main 07522 
C :: c program for airthmetic operators 
C :: timespec c 
C :: increment c 
C :: analog clock c code for turbo 
C :: online code runner .c 
C :: change no_turbo 
C :: how much larger integer i can input in c language? 
C :: why return 0 is written at the code end? 
C :: How to get the number of characters in a string without using strlen function 
C :: function of science writing of a number 
C :: passing an array of unspecified number of variables to a function 
C :: change variable type in c 
C :: print binary c 
C :: i2c scanner 
C :: c check if is a right triangle 
Dart :: dart regex for email 
Dart :: flutter divider 
Dart :: flutter appbar width 
Dart :: Container border left 
Dart :: dart timer delay 
Dart :: date now dart 
Dart :: floating action button rectangle flutter 
Dart :: generate method o dart list 
Dart :: convert string to float .0 dart 
Dart :: image from assets in flutter 
Dart :: how to give bottom padding in Listview in flutter 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =