We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
First i regard 0 as an integer with type cast (int)0, so now i have 00000...0 on it's binary representation, i negate all bits with !, thus we have 1111...1 on binary form, at the end i cast it to an unsigned type. Note that on signed type, the last bit is for the sign of number, that the number is + or -, this means that we only have 31 bits for saving numbers and one bit for the sign of them, but when i cast it to unsigned type, we have 32 bits for saving non-negative integer, thus without knowing the machine size of integer, we create the biggest positive number -on unsigned int range- that is possible on machine.
Day 6: Let's Review
You are viewing a single comment's thread. Return to all comments →
First i regard
0as an integer with type cast(int)0, so now i have00000...0on it's binary representation, i negate all bits with!, thus we have1111...1on binary form, at the end i cast it to an unsigned type. Note that on signed type, the last bit is for the sign of number, that the number is+or-, this means that we only have 31 bits for saving numbers and one bit for the sign of them, but when i cast it tounsignedtype, we have 32 bits for saving non-negative integer, thus without knowing the machine size ofinteger, we create the biggest positive number -onunsigned intrange- that is possible on machine.