Looking for a shorter way of equating


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185

    Question Looking for a shorter way of equating

    Hi there,
    I am wondering if there is a much shorter way of doing this?

    Code:
    'VARX is a word.
    
    VARX = 56789 
    'I need digit4 and digit3 (56) from this number in to a byte variable; 
    
    'I do it in this way:
    VAR_Fisrt = (VARX DIG 4)*10 + (VARX DIG 3)
    'This gives me 56.
    
    'I also need digit2 and digit1 (78) in to another byte variable;
    'I do it in this way:
    VAR_Second = (VARX  DIG 2)*10 + (VARX DIG 1)
    ' This gives me 78.


    Thanks inn advance.
    Last edited by sayzer; - 6th August 2006 at 19:10.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    sayzer,

    Don't know if it's any better or not, but here's a different way.
    VARX = 56789
    'I need digit4 and digit3 (56) from this number in to a byte variable;

    'I do it in this way:
    VAR_Fisrt = (VARX DIG 4)*10 + (VARX DIG 3)
    'This gives me 56.
    VAR_Fisrt = VARX / 1000

    'I also need digit2 and digit1 (78) in to another byte variable;
    'I do it in this way:
    VAR_Second = (VARX DIG 2)*10 + (VARX DIG 1)
    ' This gives me 78.
    VAR_Second = (VARX / 10) // 100
    <br>
    DT

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Thanks DT, but what about the rounding?

    I thought that it is going to round the result when divided by 1000.
    In our case, we should be getting 56 dividing by 1000, but since the next digit is 7 which is over 5, the actual result will be 57 (56 will be rounded to 57)

    Or is it not?
    Last edited by sayzer; - 7th August 2006 at 08:32.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Nope,

    No rounding involved. It only gives the integer value of the division.

    DT

Similar Threads

  1. Shorter Subroutines for MAX7219
    By exelanoz in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th March 2007, 11:35
  2. Equating Ports to Data Bits
    By Osiris in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd March 2006, 15:00

Members who have read this thread : 0

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