Best way to join two variable in one


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2016
    Posts
    60

    Default Best way to join two variable in one

    I am downloading some data from a cloud, collecting the ascii characters in a byte array. Now I need to use some of the numbers received, so I have to move them into a word variable.

    What I am doing at the moment is:

    W0 = ((b0-48)*100) + ((b1-48)*10) + (b2-48)

    Where:

    b0 = "6"
    b1 = "5"
    b2 = "3"

    W = 653

    Is there a better way to covert ascii to number?


    Alberto

    Edited:
    Why the thread title cannot be edited?
    Last edited by Alberto; - 27th January 2017 at 11:56.

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Best way to join two variable in one

    Alberto, The way you are proposing is just fine. I use a method similar when entering ascii text numeric like this:
    CASE $30,$31,$32,$33,$34,$35,$36,$37,$38,$39 '0,1,2,3,4,5,6,7,8,9
    TARGETEMP = TARGETEMP * 10 'NUMERIC KEY JUST RELEASED SO ADD TO VALUE
    TARGETEMP = TARGETEMP + (CHARACTER - $30)

    That way you can enter as many numeric as possible. (up to 10 if using LONGS)
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Jun 2016
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: Best way to join two variable in one


    That way you can enter as many numeric as possible. (up to 10 if using LONGS)
    Thank you Dave for the answer. I thought there cold be a magic way like when converting a variable into ascii using "dec".

    I never used long (I don't even know how to commence) can you give me some hint?

    I am running short of memory space ( using pic18f2620) could long create memory problem?

    Thank you again for your support.

    Alberto

  4. #4
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Best way to join two variable in one

    What is the biggest number you want to convert? if it's less than 65,536 then WORDs are fine...

  5. #5
    Join Date
    Jun 2016
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: Best way to join two variable in one

    I need to convert 24 Hours in seconds, so the number span from 1 to 86400 which cannot be handled by a word. Now I am using the workaround using a 12 Hours system, which complicate a bit the coding, since the source time base is 24 Hours.

    Long could be a solution, but I need a break on the coding and learn how to use the long and then, with the knowledge, decide if use it or leave the things as they are. (After all the workaround works fine!)

    I was asking for a snippet on how to use the long, good starting point in the learning process.

    Thank you anyway.

    Allberto

    Edited: I did search into pbp3 user manual and didn't find any reference to long! Where have I to search?
    Last edited by Alberto; - 29th January 2017 at 10:38.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Best way to join two variable in one

    compiling for longs is wasteful of resources and slows your prog down . if you don't really need them don't do it , there are many ways to avoid it .
    start here
    http://www.picbasic.co.uk/forum/show...ighlight=div32
    Warning I'm not a teacher

  7. #7
    Join Date
    Jun 2016
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: Best way to join two variable in one

    Thank you Richard, very interesting link. I thing I will try to use Darrel macro for big number!

    Alberto

Similar Threads

  1. Assigning a string variable to another string variable
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd June 2013, 18:55
  2. Variable within Variable
    By munromh in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th January 2009, 15:44
  3. Strings......and how to join them
    By gringobomba14 in forum General
    Replies: 17
    Last Post: - 22nd July 2008, 15:15
  4. One variable made up of another variable
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 1st September 2007, 01:18
  5. 2 variable
    By isaac in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th May 2004, 22:59

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts