How to bitwise shift a Negative Number ?

May 24, 2010 No Comments » Hits : 24






Tags : Bit wise Operator : Left Shift ,Negative number Shifing

#include<stdio.h>
void main()
{
printf("%x",-1<<4);
}

Answer :

  • Internal Representation of “-1″ is all 1′s 1111 1111 1111 1111
  • When left shifted four times the least significant 4 bits are filled with 0′s .
  • Format Specifier “%x” Prints specified integer value as “Hexadecimal Value”.
  • After Shifting  [ 1111 1111 1111 0000 ] = FFF0 will be Printed.
[1111 1111 1111 1111] << 4

After First  Shift : [1111 1111 1111 1110]
After Second Shift : [1111 1111 1111 1100]
After Third  Shift : [1111 1111 1111 1000]
After Fourth Shift : [1111 1111 1111 0000]

Related Articles:

Leave A Response