Page 1 of 1

find how many times a number appears inside a number

Posted: Thu Oct 06, 2016 9:24 pm
by matteus
I've a u16 from 1 to 200, I display the number as 3 images from 1 to 9. So if I had 211 it would be 3 image [2] [1] [1].

The problem is I'm struggling to do the calculation to work out how many 100, 10s and 1s are in the u16!

I thought the below code would work but it doesn't :/ can someone help me?

Code: Select all

           
           mod = fix16ToRoundedInt(intToFix16(GameVariables.ConcertEnergy) % 100);
            intTemp1 = fix16ToRoundedInt(intToFix16((GameVariables.ConcertEnergy) - FIX16(mod) / 100));
            mod = fix16ToRoundedInt(intToFix16(GameVariables.ConcertEnergy % 10));
            intTemp2 = fix16ToRoundedInt(intToFix16((GameVariables.ConcertEnergy - FIX16(mod)) / 10));
   

Re: find how many times a number appears inside a number

Posted: Thu Oct 06, 2016 10:25 pm
by Grind
the modulus opoerator won't work right with fixed point numbers, have to convert to int first.

Re: find how many times a number appears inside a number

Posted: Fri Oct 07, 2016 11:40 am
by matteus
Grind wrote:the modulus opoerator won't work right with fixed point numbers, have to convert to int first.
Thanks grind I knew something wasn't quite right.