0
$\begingroup$

I'm just starting to learn about representing numbers in sign-and-magnitude and two's complement, and both as signed binary integers two's complement if representing a negative number I should invert all bits and add one, while sign-and-magnitude represents negative numbers with the first bit as a sign bit, but is it possible whether I can tell if a number is represented in sign-and magnitude or two's complement from just looking at it?

$\endgroup$
2
  • $\begingroup$ Only looking at binary you cannot even say is it signed or unsigned. Everything depends on interpretation. This is why we need types. $\endgroup$
    – zkutch
    Jun 19, 2022 at 6:08
  • $\begingroup$ (Only looking at a binary representation of an integer I couldn't tell little endian from big endian, unsigned from signed. And in addition to signed and two's complement, there's biased and some more representations that have fallen out of favour (for a reason).) Interpretation is the difference. $\endgroup$
    – greybeard
    Jun 19, 2022 at 8:24

1 Answer 1

1
$\begingroup$

Every string of bits can be interpreted both as a two's complement or a sign-and-magnitude number. So the answer is clearly no.

[Usually, sign-and-magnitude allow negative zero; if not in your context, then you could say that $100\cdots0$ is a two's complement number, anyway.]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.