iPhone Programmer’s Calculator

For all of those software/firmware/hardware programmers out there with iPhones reading my blog (…all one of you: me…), I did some work on a “real” calculator last night and put the finishing touches on it today at lunch:

calc.png

For the techies: it’s implemented entirely in JavaScript using primitive datatypes (meaning the range isn’t the greatest in the world.) I’m sure someone out there has a bignum/bigint library implemented in JavaScript. It also doesn’t really like natural numbers too well. I didn’t even implement the decimal-point button because of this (although you can still get decimals by dividing things.) I am debating whether I should just chop everything down to an integer and forget about it. It also doesn’t handle negative numbers very well. You start getting into issues with number of bits and two’s complements that I didn’t feel like dealing with yet. Still, for simple base conversions, bit-shifts, and and/or masking, it’s the best (well, only) solution out there.

You can give it a try in your desktop browser, but be aware that it has been designed for the iPhone’s Safari and has only been tested with Safari and Firefox.

Posted in: Code iPhone

6 thoughts on “iPhone Programmer’s Calculator”

  1. Yeah, I kinda cheated on my own calculator and masked all my bitwise ops to 31 bits to avoid the sign issues. I really do like how you have the buttonpresses flash, BTW.

  2. I’m looking for a hot coder to do an iPhone specialized calculator AP ASAP.

    Do you or any one you know do such things?

    Call to discuss Bill 970 309 4595

  3. @Bill: I can’t really help you there. When it comes to Cocoa/iPhone programming, I’m still in my learning stages. Incidentally, I picked up a native iPhone calculator called PCalc that does exactly what I need.

  4. Hi Brian,

    I had exactly this need 6 months ago – a calculator that did proper signed and unsigned arithmetic. I couldn’t find anything that fitted my needs. So I wrote my own – Calcuccino.

    http://www.calcuccino.com

    Calcuccino has all the things you’d expect from a programmers’ calculator:

    – Bin, Oct, Dec, Hex
    – Shifts and rotates
    – Variable integer size from 2-64 bits
    – Signed, unsigned and floating point operations
    – Bitwise logic (AND, OR, XOR, NOT, MOD etc…)
    – Scientific functions (trigonometry, powers)
    – History

    What I didn’t want was a calculator that had a million tiny buttons – difficult to use reliably on an iPhone. So, I use iPhone’s menus and swipe gestures to provide the kind of UI that isn’t possible on a standard calculator. This allows:

    – 15 user-defined buttons of which 5 are visible at a time – swipe to see more
    – Interactive ASCII table – swipe the keyboard to reveal
    – All number format changes in the display (eg. number base or scientific format) are done by swiping the display

    Oh, and it looks stunning too!

    Anyway, I hope this helps provide another option for iPhone users looking for a decent calculator for programming.

    1. @Andy: Yeah, I wrote that as a junky HTML/JavaScript app back before there was a real SDK for the iPhone. These days, my go-to calculator is PCalc, but I’ll check yours out. I have to say I like your ASCII table and favorites bar.

Leave a Reply to Bill Cancel reply

Your email address will not be published. Required fields are marked *