something similar to DEC command


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    72

    Default something similar to DEC command

    hello all

    as i understand right, dec (on hserout) and # (on serout) writes a number sign by sign out.

    now, i am searching for something similar: a value (byte or word) that i should be able to handle it sign by sign.
    for example: 2009 as word variable named year

    byte a = 2
    byte b = 0
    byte c = 0
    byte d = 9

    how can i access it like an substring.... something like a = year[0]...?
    i mean that i saw a solution already somewhere in the forum, but i am not able to remember what i am should searching for.... :-(

    thanks for a hint
    i know it's only microcontrolling, but i like it!

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    You can do it with an array.
    Code:
    year var byte[4]
    
    year[0] = 9
    year[1] = 0
    year[2] = 0
    year[3] = 2
    Or, if it suits you, you could do:
    Code:
    year var byte[2]
    
    year[0] = 9
    year[1] = 20
    With the second, you would save a few bytes, but you would have to add in a zero for display purposes, so I guess you would not save anything.

    You could also do it with:
    Code:
    year var word
    year = 2009
    This would save you the space, and look a little cleaner.

    On the last one, if you wanted to get the digits separately, you can use:
    yeardigitone = year DIG 0 (would be 9)
    yeardigittwo = year DIG 1 (would be 0)

    etc. This will fetch the digit (DIG) specified.
    Last edited by ScaleRobotics; - 16th May 2009 at 17:43.
    http://www.scalerobotics.com

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mischl View Post
    hello all

    as i understand right, dec (on hserout) and # (on serout) writes a number sign by sign out.

    now, i am searching for something similar: a value (byte or word) that i should be able to handle it sign by sign.
    for example: 2009 as word variable named year

    byte a = 2
    byte b = 0
    byte c = 0
    byte d = 9

    how can i access it like an substring.... something like a = year[0]...?
    i mean that i saw a solution already somewhere in the forum, but i am not able to remember what i am should searching for.... :-(

    thanks for a hint

    The DIG directive ought to work

    a = year DIG 3
    b = year DIG 2
    c = year DIG 1
    d = year DIG 0

Similar Threads

  1. My code for TV remote and MIBAM for RGB control
    By idtat in forum Code Examples
    Replies: 4
    Last Post: - 12th January 2013, 20:52
  2. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  3. LCDout $FE,2, dec Days - What is dec ?
    By merc07 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th June 2009, 04:03
  4. Can I do this???
    By noobie in forum mel PIC BASIC
    Replies: 2
    Last Post: - 10th June 2006, 18:57
  5. Interupts and Command string
    By Tissy in forum Serial
    Replies: 13
    Last Post: - 17th March 2006, 23: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