Why can’t I store the value '4294967295' in a 4-byte integer?

Asked

Viewed 107 times

3

I wonder why I can’t store the value '4294967295' in one int of 4 bytes and the quoted value converted to binary gives exactly 4 bytes (or 32 bits)?

1 answer

6


'Cause he can’t fit in int. The int has both positive and negative numbers. Because of this it goes up to 2147483647, precisely because it goes from -2147483648 to 2147483647.

Note that both the uint32 as to the int32 have 4 bytes and also have 4294967296 possible numbers. The difference is that one starts from scratch and the other doesn’t, you will be able to use the 4294967295 if you use the uint. This is because one of the bits will be used as a given instead of a signal. The int uses a bit as a signal, while 1 is negative, for example.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.