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 276793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:58:34+00:00 2026-05-12T00:58:34+00:00

On left shift of (char) 0xff by 8 and casting it to int we

  • 0

On left shift of (char) 0xff by 8 and casting it to int we get -256 or 0xffffff00.
Can somebody explain why this should happen?

#include <stdio.h>
int main (void)
{   
    char c = 0xff;
    printf("%d %x\n", (int)(c<<8),(int)(c<<8));
    return 0;
}

Output is

-256 ffffff00
  • 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-05-12T00:58:34+00:00Added an answer on May 12, 2026 at 12:58 am

    char can be signed or unsigned – it’s implementation-defined. You see these results because char is signed by default on your compiler.

    For the signed char 0xFF corresponds to −1 (that’s how two’s complement work). When you try to shift it it is first promoted to an int and then shifted – you effectively get multiplication by 256.

    So it is this code:

    char c = 0xFF; // -1
    int shifted = c << 8; //-256 (-1 * 256)
    printf( "%d, %x", shifted, shifted );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone explain to me what does the shift left syntax in ruby means?
Consider this code: x = 1 # 0001 x << 2 # Shift left
I can recognize when the user presses any Shift key with this code: -(void)flagsChanged:(NSEvent
#include<stdio.h> int main() { printf(%x,-2<<2); //left shift of a negative integer return 0; }
Based on the following simple program the bitwise left shift operator works only for
I'm trying to find a way to perform an indirect shift-left/right operation without actually
How do I bitwise shift right/left in VB.NET? Does it even have operators for
Im trying to shift my array left as efficiently as possible. Im using pointers
Let's say I want to bit shift i twice to the left and store
People keep telling me instead of writing shift 1 bit to the left, just

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.