Hy! Sorry for my bad english, anyway questions:
I have this code in objective-c:
unsigned int a = 1; int b = -2 if (b < a);
I expect true, and if(b < a) is false instead, why?
if(b < a)
C automatically converts -2 to unsigned int into comparison. As a result, the comparison is actually (4294967294 <1), which is not so.
You compare signed with unsigned. The signed value is raised to unsigned, resulting in a large number ( 0xFFFFFFFD , I think), which is definitely greater than 1
0xFFFFFFFD
For comparison, int b is used for a variable without an signed temporary variable. This means that it ends with a big one.
See the rules here: http://msdn.microsoft.com/en-us/library/3t4w2bkb(VS.80).aspx
Put "unsigned".
If you look at the binary representation of -2 and then use this binary value as an unsigned int, then b> a
Hope this helps!
You cannot compare signed and unsigned numbers. Most likely, unsigned gets an increased value with a sign, which leads to undefined behavior or a really large number (depending on how the negative value was stored).
Source: https://habr.com/ru/post/1335337/More articles:jQuery select parent image element a - jquerycapture thread flow in SQL Server - sql-serverError "Attempted to read or write protected memory" when Win7 - ActiveX - .net control failsHow to populate gridview in XML - androidConvert Powerpoint to Flash on Linux - flvHow to expand the widget to include new features? - jqueryConvert PowerPoint to flash - actionscriptFix error 404: missing parameters from GET request on CherryPy - jsonuse of Autofac in layered architecture - asp.net-4.0Error when GetReadableDatabase crashes - androidAll Articles