Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

programering

How to split up an integer in different parts

This topic is 5436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I split up an integer in different parts? For example how do I get an integer 731245 to 73, 12 and 45? I can''t figure it out how to operate it. int sum = 731245; short a, b, c; a = ? b = ? c = ? (ex.)134578 integer to 13, 45 and 78? ------------------------------- Anton Karlsson Klingis Entertainment Games with silly humor Aleph One (Marathon Open Source) | My Homepage Packa bajs med winzip! Just dreaming wont make you (more) skilled in game programming/development.

Share this post


Link to post
Share on other sites
Advertisement
do you mean how do you divide it up into units, tens, hundreds, thousands etc?

if you do

int remainder = sum % 10;

it gives you the remainder as a result of dividing by ten. That should point you in a useful direction.

% is the modulus operator. There is a whole branch of mathematics concerning number theory which comes up with some amazing theories and proofs using modulo.

Share this post


Link to post
Share on other sites
c = sum % 100;
sum /= 100;
b = sum % 100;
a = sum / 100;


(I think ... LOL)



"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!