what is output of the following statetment?Printf(“%x”,
-1<<4); ?

Answer Posted / arupananda

Question is -1<<4
Answer to 16bit compiler
As -1 is a negative number,so compiler first convert this number with removing negative sign to 2's complement
Here -1 is given
so compiler first removes the -ve sign and then convert to 2's complement
Binary form of 1 for 16 bit compiler is 0000 0000 0000 0001
1's complement of 1 is 1111 1111 1111 1110
2's complement of 1 is 1111 1111 1111 1111(1+1's complement)
now do the left shift operation
1111 1111 1111 1111 << 4
which results 1111 1111 1111 0000
i.e equivalent to FFF0 in hex format
So the answer is FFF0 for 16 bit compiler
And for 32 bit compiler it is FFFF FFF0 (do same operation as 16 bit compiler)

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can you be sure that a program follows the ANSI C standard?

1135


What is indirection?

657


Is fortran still used today?

609


Write the test cases for checking a variable having value in range -10.0 to +10.0?

1822


What is c mainly used for?

601






Describe the steps to insert data into a singly linked list.

626


Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.

707


How can I do graphics in c?

599


Is Exception handling possible in c language?

1588


Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

2618


How does normalization of huge pointer works?

644


Write a simple code fragment that will check if a number is positive or negative.

712


When is a null pointer used?

644


What is a const pointer in c?

675


Is javascript written in c?

586