Thursday 14 March 2013

Output in Hexadecimal


main()
{
      printf("%x",-1<<4);
      printf("%x",4>>-1);

}
Answer:
fff0
0fff
Explanation :
-1 is internally represented as all 1's
1111 1111 1111 1111

When left shifted four times the least significant 4 bits are filled with 0's.
1111 1111 1111 0000

  f   f    f    0

The %x format specifier specifies that the integer value be printed as a hexadecimal value.


Blog Author: Vijay Kumar

Go to: Java Aptitude

No comments:

Post a Comment