Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

oxcug

macrumors newbie
Original poster
Oct 3, 2011
24
0
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

011

I want to add a bit to this number making it 100 (4) instead of 012.
 
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

011

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

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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.