please help me to understand the output

 void main()
    {
    printf("%x",-1<<4);
    return ;
    }

-1 is represented as 1111 1111
so in hexadecimal form it should be FFh
but compiler displays ffff ffff

Binary for -1 is 1111 1111

So when you make a left shift by 4 bits it becomes 1111 0000

Convert 1111 0000 to HexaDecimal Format You'll get ffff ffff0

So Fella Compiler is Correct.

**
Correct me If i'm wrong somewhere.**

That's because "%x" is an unsigned hex 32-bit integer on 32-bit compilers. See this article.

while converting decimal to hexdecimal we club 4 bits together.
so
1111 0000 should be F O

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.