Skip to content

Instantly share code, notes, and snippets.

@pbrewczynski
Last active January 3, 2016 00:29
Show Gist options
  • Save pbrewczynski/8383422 to your computer and use it in GitHub Desktop.
Save pbrewczynski/8383422 to your computer and use it in GitHub Desktop.
NSUInteger desiredNumber = 30;
NSMutableString *binaryRep = [[NSMutableString alloc] init];
int lastBit = (1 << 31);
NSLog(@"%d", lastBit);
for(int i = 0; i < 32; i++) {
if (desiredNumber & (lastBit))
[binaryRep appendString:@"1"];
else
[binaryRep appendString:@"0"];
desiredNumber <<= 1;
}
NSLog(@"Binary representation of a is %@", binaryRep);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment