The DIG operator i Spin
Moskog
Posts: 554
Hello there!
I'm diving into the Propeller world and hope to dive so deep that I can understand the Spin language as good as PBasic. Everything is real difficult right now but I begin to understand a few things here.
But I got this problem when trying to transform a PBasic subroutine into a PUB methode.
It is the DIG-operator in PBasic, like this:
Temp = number DIG (index)
In this part of a routine I pull out each digit one by one of a big number, like in a number 5678 the Temp will be 7 if index = 3.
How do I do this in Spin?
I'm diving into the Propeller world and hope to dive so deep that I can understand the Spin language as good as PBasic. Everything is real difficult right now but I begin to understand a few things here.
But I got this problem when trying to transform a PBasic subroutine into a PUB methode.
It is the DIG-operator in PBasic, like this:
Temp = number DIG (index)
In this part of a routine I pull out each digit one by one of a big number, like in a number 5678 the Temp will be 7 if index = 3.
How do I do this in Spin?
Comments
If you need to extract the numbers to format it as a string you can use the readily available objects (numbers and simple_numbers).
Moreover if you check the objects you'll find a lot of code to handel that.
Anyway the solution is to combine / and // (the two division operators).
If you take 5678, and want to extract the 3rd digit, you can do something like that:
(5678/10)//10
5678/10 gives 567 (you must set the right power of 10 to extract the right digit)
567//10 gives 6 (this part applies in every case)
Massimo
Thank you so much, that was a very simple solution and it works perfect.
Now I can shift eight digits one by one through a MAX7219 and right into an eight digit display without problems.
This is really getting fun!
Nice, I will be keeping your code as signed values also are a part of our life. Thank you!