PDA

View Full Version : something similar to DEC command



mischl
- 16th May 2009, 17:02
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

ScaleRobotics
- 16th May 2009, 17:16
You can do it with an array.


year var byte[4]

year[0] = 9
year[1] = 0
year[2] = 0
year[3] = 2

Or, if it suits you, you could do:


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:


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.

Chris Barron
- 21st May 2009, 23:24
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