Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's a stupid question as:</p> <ul> <li>whether a 0 or a 1 is added at the left isn't universally defined for negative numbers (Wikipedia says "vacant bit-positions are filled in, <em>generally</em> with zeros" - my emphasis)</li> <li>the integer size involved isn't discussed, and</li> <li>there are multiple bitwise representations of negative numbers in use.</li> </ul> <p>Some languages (like Java I believe) the new most-significant bits such that any platform that doesn't have a suitable CPU instruction will have to issue several to calculate the required answer, whereas other languages may make an implementation-defined choise between the behaviours the CPU natively offers.</p> <p>2's complement is the most common representation of negative numbers. Your question states "2's complement of -28 is 11100100."... I'm guessing that wasn't provided as part of the question (a bit weird if so, as it's after the answers). Still...</p> <p>If we run with 2's complement...</p> <pre><code>11100100 &gt;&gt; 3 = 00011100 or 11111100 = 28 or -4 </code></pre> <p>If the representation was 1's complement:</p> <pre><code>11100011 &gt;&gt; 3 = 00011100 or 11111100 = 28 or -3 </code></pre> <p>If the representation was sign-bit, absolute-value:</p> <pre><code>10011100 &gt;&gt; 3 = 00010011 or 11110011 = 19 or -(127-12)=-115 (note that the question says a logical bit shift, which by definition ignores any possible interpretation of the bits, so the sign bit is shifted along with others) </code></pre> <p>Re #bits in an int... I think it's so obvious that that would either result in a value that's too large to match any of the options, or else it wouldn't make any difference (if 1s are being added at left for a 1's or 2's complement), that we can ignore that issue.</p> <p>So, unless my quick calculation above slipped up, -3 is the only answer that could be correct on any plausible architecture, but is still very unlikely. All up, I'm wondering if they weren't actually testing to see who had the confidence to leave the question unanswered, or annotate that none of the answers were likely correct....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload