easy way to Add in base 2 with Obj-C?

Discussion in 'iOS Programming' started by oxcug, Feb 1, 2012.

  1. macrumors newbie

    Oct 3, 2011
    I am trying to create a binary calculator in Objective-C. Is there an easy way to add a bit to a base 2 number in the decimal system? So for example, I have


    I want to add a bit to this number making it 100 (4) instead of 012.
  2. Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
  3. macrumors 68030


    Sep 2, 2008
  4. macrumors Pentium


    Jan 28, 2009
    Quebec, Canada
    You're representing your binary how exactly ? A string ? An integer value ? An "integerized" binary number (storing decimal 11 to mean 2, etc..).

    Some details/code would go a long way to helping us help you.

    If you're just storing integers, then obviously, adding a bit means simply incrementing by 1.
  5. macrumors 68040

    Feb 2, 2008
    If you add 1 to 011 and get 12, then 011 is really eleven not three. You can not work directly with binary values in C, you have decimal, octal and hex representations available.

    You should probably start with creating methods for converting to/from binary strings and integer variables, then you can operate on those variables. The methods would only be used to get and present input to the user.

Share This Page