How to breakout lsd/msd into different variables?

gengis

New Member
I want to take a word variable and put each of three/four digits into separate variables- thousands, hundreds, tens, units with the ultimate goal of flashing an led to visually indicate temperature from a remote sensor - differentiating the numbers with longer pauses between digits and/or different colors. On an 08M . . .

I think I see a way- but doubtless it would be spaghetti code:
divide by 1000, put the result in a byte variable, subtract it from the total number, then divide the remainder by 100 and put that result in another variable, etc..

Is there a more elegant way to do this (or what is the "right" way to do this)?
 

hippy

Ex-Staff (retired)
Code:
tenThousands = w0 / 10000 // 10
thousands    = w0 / 1000  // 10
hundreds     = w0 / 100   // 10
tens         = w0 / 10    // 10
units        = w0 / 1     // 10
Optimised ...
Code:
tenThousands = w0 / 10000
thousands    = w0 / 1000  // 10
hundreds     = w0 / 100   // 10
tens         = w0 / 10    // 10
units        = w0         // 10
 

westaust55

Moderator
compact/optimised code

Couldnt you just use the Bintoascii command to do the same thing.
Thought about that myself but discounted the BINTOASCII command, as that command alone takes more program space than hippys multi-line code and then there is still the need to subtract $30 from each digit as BB has also indicted so ultimately hippys code is way more compact.
 
Top