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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:19:02+00:00 2026-06-04T21:19:02+00:00

The following program gives a signed/unsigned mismatch warning: #include <iostream> int main() { unsigned

  • 0

The following program gives a signed/unsigned mismatch warning:

#include <iostream>

int main()
{
unsigned int a = 2;
int b = -2;

if(a < b)
    std::cout << "a is less than b!";

return 0;
}

I’m trying to understand the problem when it comes to mixing signed and unsigned ints. From what I have been told, an int is typically stored in memory using two’s complement.

So, let’s say I have the number 2. Based on what I understand it will be represented in memory like this:

00000000 00000000 00000000 00000010

And -2 will be represented as the one’s compliment plus 1, or:

11111111 11111111 11111111 11111110

With two’s compliment there is no bit reserved for the sign like the “Sign-and-magnitude method”. If there is no sign bit, why are unsigned ints capable of storing larger positive numbers? What is an example of a problem which could occur when mixing signed/unsigned ints?

  • 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-04T21:19:04+00:00Added an answer on June 4, 2026 at 9:19 pm

    I’m trying to understand the problem when it comes to mixing signed and unsigned ints.

    a < b

    By the usual arithmetic conversions b is converted to an unsigned int, which is a huge number > a.

    Here the expression a < b is the same as:

    2U < (unsigned int) -2 which the same as:

    2U < UINT_MAX - 1 (in most two’s complement systems) which is 1 (true).

    With two’s compliment there is no bit reserved for the sign like the “Sign-and-magnitude method”.

    In two’s complement representation if the most significant bit of a signed quantity is 1, the number is negative.

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

Sidebar

Related Questions

I am trying to compile the following program: #include <iostream> int main(){ std::cout <<
Following program gives error #include<stdio.h> int main () { int a=10,b; a>=5?b=100:b=200; printf(\n%d,b); }
The output of following program #include<stdio.h> int main(){ int *p[10]; printf(%ld %ld\n,sizeof(*p),sizeof(p)); } is
Consider following program: static void Main (string[] args) { int i; uint ui; i
Given the following snippet: #include <stdio.h> typedef signed long long int64; typedef signed int
the program gives following exception: Exception in thread main java.lang.NullPointerException at myclasses.BubbleSort.run(BubbleSort.java:42) at acm.program.Program.runHook(Program.java:1519)
I have the following code: #include stdafx.h #include <iostream> #include <conio.h> using namespace std;
I have been trying to understand of this following C-program: #include <stdio.h> int arr[]
The following program gives me a bus error... any ideas why? program main integer,
When I run the java program it gives following error: Exception in thread main

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.