In the link and in support of @vincent osinga answer .. Here is this code wrapped in a C-function .. that returns a binary "string" from NSUInteger .. ideal for logging bitwise typedef, etc.
- (NSString*) bitString:(NSUInteger) mask{ NSString *str = @""; for (NSUInteger i = 0; i < 8 ; i++) { // Prepend "0" or "1", depending on the bit str = [NSString stringWithFormat:@"%@%@", mask & 1 ? @"1" : @"0", str]; mask >>= 1; } return str; }
I do not think NSInteger numberCopy = theNumber; necessary because you are not using a pointer, but simply a primitive value as an argument // so you won't change your original value . This will allow use as results / results such as ...
NSEventType anEvent = NSLeftMouseUp|NSLeftMouseDown; NSLog(@"%@, %u\n%@, %u\n%@, %u\n%@, %u", bitString( NSScrollWheel), NSScrollWheel, bitString( NSLeftMouseUp|NSLeftMouseDown), NSLeftMouseUp|NSLeftMouseDown, bitString( anEvent ), anEvent, bitString( NSAnyEventMask ), NSAnyEventMask);
NSLOG ➞
00010110, 22 00000011, 3 00000011, 3 11111111, 4294967295
source share