Convert decimal to binary

Helps to understand how binary count works:

- (NSString *)divideByTwo: (NSInteger) decimalNumber
    NSMutableString *binary = [[NSMutableString alloc]init];
    if (binary == 0) {
        [binary appendString:@"%@"];
    while (decimalNumber > 0) {
        NSInteger rem = decimalNumber % 2;
        [binary appendString:[NSString stringWithFormat:@"%d", rem]];
        decimalNumber = decimalNumber / 2;
    return binary;

There is also Any base converter on Github, which is a general case of base 2 conversion. It converts any decimal number to any base from 2 to 16 and mimics a stack behavior.

NSNumber vs NSInteger

The notion of NSInteger and NSNumber may seem confusing at first glance, but in reality it is simple.
NSNumber is a subclass of NSValue – container for C or Objective-C data item. The purpose of NSValue class, and, hence, NSNumber class – to allow items of different data types (ints, floats, chars, pointers, structures, as well as object ids) to be added to collections, such as instances of NSArray, for example. As simple is that!

With that purpose in mind, it’s easy to memorize NSNumber features:
1. it stores and retrieve primitives, but it’s NOT primitive;
2. it can be displayed using %@ format specifier;
3. it is incredible useful when we need to stick a number into NSArray of NSDictionary.

NSInteger also has some features:
1. it is very much like traditional int in C, only it save us from dealing with int/long on 32/64 bit processor architecture;
2. it is a primitive.

We can convert them between each other:

NSInteger myInt = [numberValue integerValue]; //NSNumber to NSInteger
//NSInteger to NSNumber
NSNumber myNum = [NSNumber numberWithInteger: integerValue]; 
NSNumber myNum = @(integer);