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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:32:56+00:00 2026-06-17T04:32:56+00:00

i have written a small program below. #include <stdio.h> main(){ char a=-1; unsigned char

  • 0

i have written a small program below.

#include <stdio.h>
main(){
    char a=-1;
    unsigned char b=-1;
    printf("%d %d\n",a,b);
    printf("%x %x\n",a,b);
    if(a==b) printf("equal\n");
    else printf("not equal\n");
}

The output of the prog is :

-1 255
ffffffff ff
not equal

since char is only one byte and -1 is represented in 2’s complement form, i thought that 0xff will be stored in both a & b and hence both should be equal. Can anyone let me know why they are different and why hex rep’n of a is 0xffffffff & not 0xff. i got a related link http://embeddedgurus.com/stack-overflow/2009/08/a-tutorial-on-signed-and-unsigned-integers/ but i couldn’t get the answer. any help will be greatly appreciated. thanks.

  • 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-17T04:32:57+00:00Added an answer on June 17, 2026 at 4:32 am

    They are the same. Or rather, their underlying representation is the same (under the assumption that your compiler use two-complement form).

    On the other hand, the values they represent are -1 and 255.

    When you print them, they are extended to the data type int. unsigned char is zero-extended whereas a signed char is sign extended, which accounts for the differences you see.

    The same extension occurs when you compare the two values. a == b don’t compare the underlying representations, instead, it extends both values to int so it compares 255 with -1, which isn’t equal.

    Note that a plain char may be either signed or unsigned. In your environment, it is obviously signed.

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

Sidebar

Related Questions

Below is a small program that I have written to count the number of
I have written a small program: void showrecord() { char *a[]={ O_BILLABLE_ACCOUNT,O_CUSTOMER_TYPE_INDICATOR, O_A_PARTY_MSISDN_ID,O_A_PARTY_EQUIPMENT_NUMBER, O_A_PARTY_IMSI,O_A_PARTY_LOCATION_INFO_CELL_ID,
I just written a small program to test something, as below: public class Main
I have written small C++ console application and this is source code : #include<stdio.h>
I have written a small program just like hello the world , everything was
I have visual studio 2008. I have a written a small C program. I
I have written a small utility to collect system data and output it to
I have written this small program in VS2010 to run on Outlook 2007. It
I have written a small program , to understand how futures work in c++0x.
I have written a small program and compiled it under Solaris/Linux platform to measure

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.