Hexadecimal addition

  • Hi

    I have an hexadecimal number in NSString. I want to add 0x1000 to my Hexadecimal number and print out the result.

    Say:
    NSString *hexString = @"2fffa";
    // I need to print
    hexString + 0x1000
    How can I do hexadecimal addition?

    Thank you
    DG

          Get the freedom to save as many mails as you wish. To know how, go to http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html
  • --- deepak gopal <deengg...> wrote:

    > I have an hexadecimal number in NSString. I want to
    > add 0x1000 to my Hexadecimal number and print out
    > the result.
    >
    > Say:
    > NSString *hexString = @"2fffa";
    > // I need to print
    > hexString + 0x1000
    > How can I do hexadecimal addition?

    It's normal integer addition you want to do -- the hex
    is just how it's displayed. You can get an integer out
    of a string with NSFormatter's scanHexInt:, and you
    can create a hex string representation of an integer
    with [NSString stringWithFormat:@"%x", anInteger]
    (though you might consider using an NSFormatter
    subclass to format the data for output rather than
    storing it that way, just as a thought).

    Cheers,
    Chuck

    __________________________________________________
    Do You Yahoo!?
    Tired of spam?  Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
  • on 11/6/07 2:05 PM, <acharlieblue...> purportedly said:

    > It's normal integer addition you want to do -- the hex
    > is just how it's displayed. You can get an integer out
    > of a string with NSFormatter's scanHexInt:, and you
    > can create a hex string representation of an integer
    > with [NSString stringWithFormat:@"%x", anInteger]
    > (though you might consider using an NSFormatter
    > subclass to format the data for output rather than
    > storing it that way, just as a thought).

    Just to correct this, -scanHexInt: is a function of NSScanner--NSFormatter
    has no such methods.

    Best,

    Keary Suska
    Esoteritech, Inc.
    "Demystifying technology for your home or business"
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today