Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8622743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:07:45+00:00 2026-06-12T07:07:45+00:00

I am trying to understand why my program #include<stdio.h> void main() { printf(%x,-1<<4); }

  • 0

I am trying to understand why my program

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

prints fffffff0.

What is this program doing, and what does the << operator do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:07:45+00:00Added an answer on June 12, 2026 at 7:07 am

    The << operator is the left shift operator; the result of a<<b is a shifted to the left of b bits.

    The problem with your code is that you are left-shifting a negative integer, and this results in undefined behavior (although your compiler may place some guarantees on this operation); also, %x is used to print in hexadecimal an unsigned integer, and you are feeding to it a signed integer – again undefined behavior.

    As for why you are seeing what you are seeing: on 2’s complement architectures -1 is represented as “all ones”; so, on a computer with 32-bit int you’ll have:

    11111111111111111111111111111111 = -1 (if interpreted as a signed integer)
    

    now, if you shift this to the left of 4 positions, you get:

    11111111111111111111111111110000
    

    The %x specifier makes printf interprets this stuff as an unsigned integer, which, in hexadecimal notation, is 0xfffffff0. This is easy to understand, since 4 binary digits equal a single hexadecimal digit; the 1111 groups in binary become f in hex, the last 0000 in binary is that last 0 in hex.

    Again, all this behavior hereby explained is just the way your specific compiler works, as far as the C standard is concerned this is all UB. This is very intentional: historically different platforms had different ways to represent negative numbers, and the shift instructions of various processors have different subtleties, so the “defined behavior” we get for shift operators is more or less the “safe subset” common to most “normal” architectures.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to understand of this following C-program: #include <stdio.h> int arr[]
I am trying to understand the disassembled version of this program: #include <stdio.h> int
I have the following program #include <stdio.h> int main(void) { unsigned short int length
I was trying to understand void pointer typecasting in C. I wrote a program
I am trying to understand how realloc works. This is my program. It's giving
I'm trying to understand concurrency in Go. In particular, I wrote this thread-unsafe program:
I am trying to understand http://beej.us/guide/bgnet/examples/select.c (included below for reference). I am doing this:
This is a program trying to make a linked list. #include <iostream> using namespace
In my program I am trying to resize array using malloc function. #include <stdio.h>
I have a file hello.c #include<stdio.h> void hello() { printf(Hello!\n); } A header hello.h

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.