Why is the value of NSUInteger 2^32 – 1 instead of 2^32? Is there a relationship between this fact and the need of a nan value? This is so confusing.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Count to 10 on your fingers. Really 🙂
The standard way to count to 10 is
1,2,3,..10(the ordinality of each finger is counted). However, what about “0 fingers”?Normally that might represent that by putting your hands behind our back, but that adds another piece of information to the system: are your hands in front (present) or behind (missing)?
In this case, putting hands behind your back would equivalent to assigning
nilto anNSNumbervariable. However,NSUIntegerrepresents a native integer type which does not have this extra state and must still encode 0 to be useful.The key to encode the value 0 on your fingers is to simply count
0,1,2..9instead. The same number of fingers (or bits of information) are available, but now the useful0can be accounted for .. at the expense of not having a10value (there are still 10 fingers, but the 10th finger only represents the value9). This is the same reason why unsigned integers have a maximum value of2^n-1and not2^n: it allows0to be encoded with maximum efficiency.Now,
NaNis not a typical integer value, but rather comes from floating point encodings – think offloatorCGFloat. One such common encoding is IEEE 754: