What is the most efficient way to get the last 2 digits of an integer into a seperate variable? What about the 3rd and 4th last?

Ex.

123456

int a should == 12

int b should == 34

int c should == 56

Printable View

- 09-19-2005CanuckleheadHelp manipulating int
What is the most efficient way to get the last 2 digits of an integer into a seperate variable? What about the 3rd and 4th last?

Ex.

123456

int a should == 12

int b should == 34

int c should == 56 - 09-19-2005sean
You can use the modulus operator to get the remainder of a division operation. If you divide a number by 100, the remainder is going to be the last two digits of that number.

Getting the third and fourth is a very similar process. Get the last four digits, then divide by 100 (integer division just drops the remainder in C++) to get the first two. - 09-19-2005Canucklehead
Great! Thanks.

In case you were wondering, this isn't homework. I'm still in high school. This is for my own personal health.