Announcement

Collapse
No announcement yet.

Convert buffer value to an integer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Convert buffer value to an integer

    I have a string:
    myInput,25,30
    this is a comma delimited string. I process it and get all characters between the first and the second comma (25), then I want to use that number in other arithmetic operations like additions and subtractions.
    I was able to get the number 25 which is now in a buffer variable. how can I convert it to an integer?
    Thank you all,
    -Halim

  • #2


    Assuming you have ASCII codes for "2" and "5" in the buffer, then
    ( ('2' - '0')
    _______________
    Best Regards,
    Howard

    Comment


    • #3
      print("\n Number: ", ( ('2' - '0')<<8) + ('5' - '0') ); //gave me 517

      print("\n", [STR] Buff ); //gives me 25

      All I want to do it take that 25 and use it as a number.
      Thank you,
      -Halim

      Comment


      • #4


        Sorry, Was thinking in terms of BYTES
        It's just : ('2' - '0')*10) + ('5' - '0'), or
        answer := ((buffer[0] - '0')*10) + (buffer[1] - '0');
        _______________
        Best Regards,
        Howard

        Comment


        • #5


          Thank you for your help. This link is helpful as well:
          http://www.4dsystems.com.au/developers/docs.php?cat=28&id=152

          Comment

          Working...
          X