So, if I understand correctly, an integer is a collection of bytes, it represents numbers in base-two format, if you will.
Therefore, if I have unsigned int test=0, is should really just consist of a field of bits, all of which are zero. However,
unsigned int test=0;
test=~test;
produces -1.
I would’ve thought that this would’ve filled all the bits with '1', making the integer as large as it can be on that system….
Thanks for any help!
How do you print the value?
If it’s displayed as “-1” or a large unsigned integer is just a manner of the bits are interpreted when printing them out, the bits themselves don’t know the difference.
You need to print it as an
unsignedvalue.Also, as pointed out by other answers, you’re assming a lot about how the system stores the numbers; there’s no guarantee that there’s a specific correlation between a number and the bits used to represent that number.
Anyway, the proper way to get this value is to
#include <climits>and then just useUINT_MAX.