How to split up an integer in different parts

Started by
2 comments, last by programering 20 years, 4 months ago
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.
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.
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
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
Yes, It''s right! thanks!

I got the idea to multiply by 0.01 (b = sum * 0.01)

-------------------------------
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.

This topic is closed to new replies.

Advertisement