Last active
January 3, 2016 00:29
-
-
Save pbrewczynski/8383422 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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