-1

This is a short question and I just wanted to clarify something.

What is the value assigned to 0xFFFFFFFF in One and Two's Complement?

I thought that 0xFFFFFFFF is Two's Complement was -1. However when I used an online Two's Complement calculator, I got a value of 1.

Also, I wanted to check if the value of 0xFFFFFFFF in One's Complement was 0.

scy17
  • 61
  • 4
  • In C, the value of 0xFFFFFFFF is 4,294,967,295. It's always positive, no matter what the hardware is. If that's not what you meant, please tell us exactly which CPU(s) you are interested in; there isn't a single answer. – zwol Jul 14 '20 at 00:31
  • in particular, on *some* historical one's complement hardware, the value of a word with all bits set is zero; on other such hardware it is instead an invalid number. – zwol Jul 14 '20 at 00:34
  • Isn't 0xFFFFFFFF, if declared as an unsigned int, assigned a value of -1? I'm not really interested in any specific CPU(s). I'm new to learning about C and number representations so apologies if the question is vague. – scy17 Jul 14 '20 at 00:36
  • I think my question should be. If x = 0xFFFFFFFF in a machine running one's complement. What value would be assigned to x? Now, if the machine used two's complement, what value would x be? – scy17 Jul 14 '20 at 00:39
  • No, really, `unsigned int x = 0xFFFFFFFF` assigns x the *positive* value 4,294,967,295 (assuming UINT_MAX is that big). – zwol Jul 14 '20 at 00:46
  • "Isn't 0xFFFFFFFF, if declared as an unsigned int, assigned a value of -1?" You have that backwards. An `unsigned int` can never be negative. If -1 is converted to a (32-bit) `unsigned int`, it would be assigned as `0xFFFFFFFF`. – jamesdlin Jul 14 '20 at 00:46
  • 1
    An interesting (to me at least) question is whether there was ever in fact a 32-bit ones-complement machine. – user13784117 Jul 14 '20 at 01:30
  • @user13784117 The last survivor of the ones-complement era is the Burroughs B-series mainframes, which, last I checked, you could still buy! I have not been able to find out their word size, but if there was ever a 32-bit ones-complement machine, I bet it was one of those. – zwol Jul 27 '20 at 02:55

1 Answers1

1

Considered as a signed 32-bit integer, FFFFFFFF is -1 in a 2's complement system, or -0 in a 1's complement system (a characteristic of 1's complement representation is that it has +0 and -0).

Considered as an unsigned 32-bit integer, FFFFFFFF is 4,294,967,295 decimal.

As pointed out, the specific notation 0xFFFFFFFF in a specific programming language may be considered as unsigned or signed, 32 bits or longer.


I don't know what a Twos Complement Calculator does, but the 2's complement of -1 is 1, and vice-versa. Possibly you were asking it for the complement of FFFFFFFF.

user13784117
  • 1,124
  • 4
  • 4