Pulling out digits from a value...?
RottenJalapeno
Posts: 27
I'm working on a program where I need the value of each digit of a variable.· Basically the VAR DIG(X) COMMAND in the BS2.· I looked around in the manual and I couldnt find anything that caught my eye.· I need to get the value of each digit so I can output the value to a 7-segment display.· I'm currently using the max7219 and I can communicate with it just fine, but my problem is breaking down the data I need to display.
And another question I have is can you declare variables at the bit level?· as far as I can see you can just break the memory up down to the byte level.· So lets say I wanted to make a boolean flag or whatnot, do you need to make flag a byte? or can you just declare it as a bit, and if so how?
And another question I have is can you declare variables at the bit level?· as far as I can see you can just break the memory up down to the byte level.· So lets say I wanted to make a boolean flag or whatnot, do you need to make flag a byte? or can you just declare it as a bit, and if so how?
Comments
Sometimes it's easier to update the many individual values, in order to have a simple display method, rather than to maintain a single variable that's easy to update but can be time-consuming or difficult to break down into the parts for display.
To access the digits of a value, just use multiplication (*) and modulus (//) by powers of 10. To get digits 3 through 0 of v, use "(v / 1000) // 10", "(v / 100) // 10", "(v / 10) // 10", and "v // 10". Clearly, with 32 bits available, you can extend this to 10 digits at least. If you want to have something more like the DIG operator, you can set up a table of long constants in a DAT section with the powers of ten and access this like "(v / table[noparse][[/noparse] i]) // 10". The table would look like:
You could even declare a DIG function like:
Post Edited (Mike Green) : 2/7/2007 8:56:31 PM GMT