Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Last active December 18, 2015 01:39
Show Gist options
  • Save odrobnik/5705353 to your computer and use it in GitHub Desktop.
Save odrobnik/5705353 to your computer and use it in GitHub Desktop.
BOOL test
// test if there is a byte trunction happening
for (int i=0; i<32; i++)
{
__unsafe_unretained id pointer = (__bridge id)(void *)(1<<i);
NSUInteger v = (int)pointer;
if (pointer)
{
NSLog(@"%d Works! v = %d", i, v);
}
else
{
NSLog(@"%d Doesn't work! v = %d", i, v);
}
}
/** Output:
2013-06-04 13:59:56.924 testbool[18112:c07] 0 Works! v = 1
2013-06-04 13:59:56.925 testbool[18112:c07] 1 Works! v = 2
2013-06-04 13:59:56.926 testbool[18112:c07] 2 Works! v = 4
2013-06-04 13:59:56.926 testbool[18112:c07] 3 Works! v = 8
2013-06-04 13:59:56.927 testbool[18112:c07] 4 Works! v = 16
2013-06-04 13:59:56.927 testbool[18112:c07] 5 Works! v = 32
2013-06-04 13:59:56.927 testbool[18112:c07] 6 Works! v = 64
2013-06-04 13:59:56.928 testbool[18112:c07] 7 Works! v = 128
2013-06-04 13:59:56.928 testbool[18112:c07] 8 Works! v = 256
2013-06-04 13:59:56.928 testbool[18112:c07] 9 Works! v = 512
2013-06-04 13:59:56.929 testbool[18112:c07] 10 Works! v = 1024
2013-06-04 13:59:56.929 testbool[18112:c07] 11 Works! v = 2048
2013-06-04 13:59:56.929 testbool[18112:c07] 12 Works! v = 4096
2013-06-04 13:59:56.930 testbool[18112:c07] 13 Works! v = 8192
2013-06-04 13:59:56.930 testbool[18112:c07] 14 Works! v = 16384
2013-06-04 13:59:56.930 testbool[18112:c07] 15 Works! v = 32768
2013-06-04 13:59:56.931 testbool[18112:c07] 16 Works! v = 65536
2013-06-04 13:59:56.931 testbool[18112:c07] 17 Works! v = 131072
2013-06-04 13:59:56.932 testbool[18112:c07] 18 Works! v = 262144
2013-06-04 13:59:56.932 testbool[18112:c07] 19 Works! v = 524288
2013-06-04 13:59:56.932 testbool[18112:c07] 20 Works! v = 1048576
2013-06-04 13:59:56.933 testbool[18112:c07] 21 Works! v = 2097152
2013-06-04 13:59:56.933 testbool[18112:c07] 22 Works! v = 4194304
2013-06-04 13:59:56.934 testbool[18112:c07] 23 Works! v = 8388608
2013-06-04 13:59:56.934 testbool[18112:c07] 24 Works! v = 16777216
2013-06-04 13:59:56.934 testbool[18112:c07] 25 Works! v = 33554432
2013-06-04 13:59:56.935 testbool[18112:c07] 26 Works! v = 67108864
2013-06-04 13:59:56.936 testbool[18112:c07] 27 Works! v = 134217728
2013-06-04 13:59:56.936 testbool[18112:c07] 28 Works! v = 268435456
2013-06-04 13:59:56.937 testbool[18112:c07] 29 Works! v = 536870912
2013-06-04 13:59:56.937 testbool[18112:c07] 30 Works! v = 1073741824
2013-06-04 13:59:56.937 testbool[18112:c07] 31 Works! v = -2147483648
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment