Author Topic: [Solved] Cut the numbers of a variable  (Read 2975 times)

0 Members and 1 Guest are viewing this topic.

Offline Axenntio

  • LV3 Member (Next: 100)
  • ***
  • Posts: 41
  • Rating: +3/-0
    • View Profile
[Solved] Cut the numbers of a variable
« on: April 08, 2014, 09:01:32 am »
Hi dear community ! :D

Since 1 days, I program a music editor in Axe, and I need to write the number of the line BUT, I want customs numbers:

Code: [Select]
[E0A0A0A0E00000004040404040000000E020E080E0000000E020E020E0000000A0A0E02020000000E080E020E0000000E080E0A0E0000000E0A0202020000000E0A0E0A0E0000000E0A0E020E0000000]->Pic0

Where is the problem ? I want separate all the part of the number: so for 125 I can have 1, 2 and 5
The number 125 is stored in the var L

After, I want display the number with:
Code: [Select]
Pt-On(2,I*6+2(,the 100th terme of M)*8+Pic0
Pt-On(6,I*6+2,(the 10th terme of M)*8+Pic0
Pt-On(10,I*6+2,(the 1st terme of M)*8+Pic0

Can you help me ? :/
« Last Edit: April 08, 2014, 09:59:15 am by Axenntio »

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Cut the numbers of a variable
« Reply #1 on: April 08, 2014, 09:48:17 am »
Ah, you want to get the decimal digits out of a number :D
The modulo operator (^) does exactly that for you. It returns the remainder of a division. Say 27/10 is 2 remainder 7, so 27^10 returns 7. There you have the first digit (units), then you divide the number by ten and do it again for the tenths and so on.
Code: [Select]
125->M
Pt-On(10,I*6+2,M^10*8+Pic0)   //units
Pt-On(6,I*6+2,M/10->M^10*8+Pic0)  //tenths
Pt-On(2,I*6+2,M/10^10*8+Pic0)  //hundreds
The original value of M is corrupted, you might want to save that before the calculation


Offline Axenntio

  • LV3 Member (Next: 100)
  • ***
  • Posts: 41
  • Rating: +3/-0
    • View Profile
Re: Cut the numbers of a variable
« Reply #2 on: April 08, 2014, 09:54:24 am »
How do I exactly forgotten the modulo... Ha... because I know it like (%)... Thank you a lot MGOS, Topic solved :3
« Last Edit: April 08, 2014, 10:00:00 am by Axenntio »

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: [Solved] Cut the numbers of a variable
« Reply #3 on: April 08, 2014, 11:31:23 am »
For even more flexibility you should use a for loop. But that's up to you. :P

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: [Solved] Cut the numbers of a variable
« Reply #4 on: April 08, 2014, 01:59:37 pm »
Here is a full code I quickly (as you can tell from the sprites) threw up as an example.

Code: [Select]
.AA

..Main Code
ClrDraw
Print(45125)
DispGraph
While 1
EndIf getKey(15)
Return

..Routines
Lbl Print
88
For(4)
 Select(,sub(Print1))-8
End
Lbl Print1
Pt-Off(,20,r1^10*8+°Nb)
r1/10->r1
Return

..Data
[]->°Nb
[007CC4C642663C00]
[0008080808080800]
[003C260303063C06]
[003C04043C2C0C38]
[103060C0F8080808]
[003EE0C07C040CF8]
[041C306078683C18]
[007E02021F1C3060]
[7E466C78584C741C]
[70D8D8780808F800]
And here is what it outputs


Change the "88" and the "20" to change the coordinates of the number. Note that "88" is the X-coordinate of the last number. You can also add a "If r1" in the "Lbl Print" to have the routine not show useless zeroes.
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s