recategorized by
722 views
3 votes
3 votes

Consider Figure $\text{A}$ and Figure $\text{B}$ which represent $4$ bit signed and unsigned numbers respectively in $2’s$ complement system.

Assume that a few variables are defined below and initialized in such a way that places them in the spot shown in Figure $\text{C}$.

int s1, s2, s3;
unsigned int u1, u2, u3;

Which of the following(s) is/are true?

  1. $s3 > u3$
  2. $s1 > s3$
  3. $u1 > u3$
  4. $s1 > u3$
recategorized by

1 Answer

4 votes
4 votes
We can take integers as $k$ bits in the system. For an easy explanation, we are taking $k =4$.
Let
$s1 = 1001
s3 = 0010$

$u1 = 1010
u3 = 0001$

$s3$ and $u3$ will be $2$ and $1$ in decimal, respectively, irrespective we treat them as signed numbers or unsigned numbers (MSb is $0$).
$s1$ is $9$ in unsigned and $-7$ in signed.
$u1$ is $10$ in unsigned and $-6$ in signed.

Option $\text{A}$:
This is an unsigned comparison i.e., $s3$ will be treated as an unsigned number.
Although MSB of $s3$ is $0$ hence, it does not matter.
$s3 > u3$ is same as $2 > 1$, which is true
Option $\text{B}$:
both are signed hence signed comparison
$s1 > s3$ is same as $-7 > 2$, which is false.
Option $\text{C}$:
both are unsigned hence unsigned comparison
$u1 > u3$ is same as $10 > 1$, which is true.
Option $\text{D}$:
one of the variables is unsigned hence unsigned comparison
$s1 > u3$ is same as $9 > 1$, which is true.
Answer:

Related questions

4 votes
4 votes
3 answers
1
GO Classes asked Aug 6, 2022
679 views
Consider the following declaration of variables $a$ and $b.$int a = 1, b = 0;Which of the following is/are will evaluate to TRUE?b++ && b == ab++ && a == 0a || b == aa |...