number conversion

U

usgog

I need some help to do number conversion...:

I got a 9 digit integer from another function (say int A = 123456789)
and need to make a 4 digit one (int B, say 6789) from A. Then I send B
to user.

User types in 4 digit integer (int C) and I check whether B == C. If
true, then I convert B to back to A again.

So how can I convert A to B and then B to A? Any algorithm I can use,
say get the last four digit of A?
 
L

Lee Weiner

I need some help to do number conversion...:

I got a 9 digit integer from another function (say int A = 123456789)
and need to make a 4 digit one (int B, say 6789) from A. Then I send B
to user.

User types in 4 digit integer (int C) and I check whether B == C. If
true, then I convert B to back to A again.

So how can I convert A to B and then B to A? Any algorithm I can use,
say get the last four digit of A?

Mod A with 10000:

int B = A % 10000;

Why do you have to convert B back to A? Don't you still have the value of A
stored in a variable? It's still there.

Lee Weiner
lee AT leeweiner DOT org
 
U

usgog

You are correct...Thanks!


Lee said:
Mod A with 10000:

int B = A % 10000;

Why do you have to convert B back to A? Don't you still have the value of A
stored in a variable? It's still there.

Lee Weiner
lee AT leeweiner DOT org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,075
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top