# Evaluating differ. parts of a single #.

This is a discussion on Evaluating differ. parts of a single #. within the C Programming forums, part of the General Programming Boards category; Suppose i have an 8 digit code. I want to assign first 'x' digits to represent the first code. The ...

1. ## Evaluating differ. parts of a single #.

Suppose i have an 8 digit code. I want to assign first 'x' digits to represent the first code. The 'y' digits after x i want to represent a different code. And so on.

So for a specified number. I want the first three digits to give value to a variable. The next three to do the same to another variable. And the second last and last to both individually do the same.

For the first three, i would:

divide the number by 100,000. This would yield a three digit code with 5 decimals. Then i would convert the double into integer, and end up with a three digit code (called "number1") which i evaluate via if statements.

For the next three:

Divide the number by 100. This would create a 6 digit number with 2 decimals. I convert into integer, creating a 6 digit integer (this is "number6". Then subtract number6 - 1000*number1. This would produce a the three digits after the first three. So in 12345678, these numbers would be 456.

However, im not sure how to do the second last and last! I was thinking of using remainders, but im unsure of how to do that.

Please, any help or suggestions would be strongly appreciated.

2. use the same math you did before... except use number7 -= ((number1*1000)+number6)*10; think about the last one. Its easy as well.

3. There are two ways to get remainders.

r = a - ((a / b) * b)

r = 123 - ((123 / 100) * 100 )
r = 123 - ( 1 * 100 )
r = 123 - 100
r = 23

The second is to simply use the modulus operator, which does it for you:

r = a % b;
r = 123 % 100;

Quzah.