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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:03:38+00:00 2026-05-23T05:03:38+00:00

signed char num = 220; //DC in hex printf(%02X\n, num); printf(%d\n, num); I know

  • 0
signed char num = 220; //DC in hex
printf("%02X\n", num);
printf("%d\n", num);

I know that signed char can only represent -128~127,but why the above outputs:

FFFFFFDC
-36

What’s the reason?

UPDATE

My above code is just contrived for my question,that is ,what happens when we cast signed char to int/hex

  • 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-23T05:03:39+00:00Added an answer on May 23, 2026 at 5:03 am

    As our starting point, 220 = DC in hex, and 11011100 in binary.

    The first bit is the sign-bit, leaving us with 1011100. Per two’s complement, if we complement it (getting 0100011), and then add one, we get 0100100 — this is 36.

    When it converts the signed char to signed int, it doesn’t say “this would be 220 if it’s unsigned”, it says “this is -36, make it an int of -36”, for which the 32-bit two’s complement representation is FFFFFFDC, because it must be the negative value for the full size of int (this is called sign-extension):

    +36 as a 32-bit value: 00000000000000000000000000100100
    complement:            11111111111111111111111111011011
    add one:               11111111111111111111111111011100
    

    Or, in hex, FFFFFFDC.

    This is why you must be careful with printf("%x", ch); (and relatives) — if you intend to just get a two-digit value, and chars are signed, you may wind up with eight digits instead. Always specify “unsigned char” if you need it to be unsigned.

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

Sidebar

Related Questions

I know BOOL is actually a typedef of signed char, but what about Boolean?
I know that the C++ standard explicitly guarantees the size of only char ,
Is this understanding correct: any integer that is not signed char, short, int, long,
I have a unsigned int that was converted to a signed char like this
I'm lead to believe that write() can only send data buffers of byte (i.e.
If I have: signed char * p; and I do a comparison: if (
The C standard states: ISO/IEC 9899:1999, 6.2.5.15 (p. 49) The three types char, signed
Given that signed and unsigned ints use the same registers, etc., and just interpret
Conside the following code: int main() { signed char a = 10; a +=
Is there a subtle trick for template specialization so that I can apply one

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.