Let x 0xA5 and y 0xABCDE and string s 1 Mask the upper 4bits

Let x= 0xA5 and y= 0xABCDE and string s.

1) Mask the upper 4bits of x

2) clear bit 6 of x

3) set bit 9 of y

4) interchange x and low 8 bits of y without using a third variable or register

5) invert x.

6) shift left x four bits and shift right y two bits.

7) check if bit 4 of x is 0.

8) check if bit 10 of y is 1.

9) suppose the length s is 5. convert y into decimal ASCII string and put it into s.

10) suppose s-\"ABCEXY\". write a c function to covert s as \"yxecba\"

(4) intercbange x dad low 8 bits of y without using a tont variabl (6) Shift left four hits and shift ti (7) Check if bit 4 of s is 0 (s) Check bit 10 of y is Suppose the length s is 5. Convert y into decimal ASCIl string and put it into s. Write a C function to covert s as \"yxecba\" ABCEXY\"

Solution

Hello Thanks for giving clear description and Typing Question from Image

x= 0xA5 and y= 0xABCDE (Hexa Decimal Numbers. In Decimal(10) X=165 and 703710)

1) Mask the upper 4bits of x

----------------------------------------------------

                                  unsigned char value = 0xa5;
                           unsigned char mask = 0x0f;
                           unsigned char mask_result = (value & mask);

2) clear bit 6 of x :-

----------------------------------------

                                 unsigned char value = 0xa5;
                           unsigned char clear = 0xfb;
                           unsigned char clear_result = (value & clear);

3) set bit 9 of y :-

-----------------------------

                                unsigned int value = 0xabcde;
                                unsigned int set = 0x800;
                                 unsigned int set_result = (value | set);

4) interchange x and low 8 bits of y without using a third variable or register :-

---------------------------------------------------------------------------------------------------------------

This is Achieved in 2 steps without using any 3rd variable

         1) Clear Low 8 bits of Y (set Low 8 bits to \"00000000\"

         2)Now do unary or(|) with X

            unsigned int x = 0x00a5;
            unsigned int y = 0xabcde;
            y = y &(1111111100000000);
             y = (y | x);

     

5) invert x :-

------------------------

             C Code

                         x = ~x;

6) shift left x four bits and shift right y two bits :-

------------------------------------------------------------------------

x = x <<4;

y = y >>2;

7) check if bit 4 of x is 0.

8) check if bit 10 of y is 1.

------------------------------------------------

                 int pos = 3 // Postion at which we have to check

                  int value = 10; //Value on which we have to check

                 if( (value &(1<<pos) ) == 1)

                  {

                             print(\"bit at pos 3 is 1\");

                   }

          check if bit 4 of x is 0

                if( (x & (1 <<4)) == 0)

Let x= 0xA5 and y= 0xABCDE and string s. 1) Mask the upper 4bits of x 2) clear bit 6 of x 3) set bit 9 of y 4) interchange x and low 8 bits of y without using a
Let x= 0xA5 and y= 0xABCDE and string s. 1) Mask the upper 4bits of x 2) clear bit 6 of x 3) set bit 9 of y 4) interchange x and low 8 bits of y without using a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site