So you have the character '1', which has a numerical value of 49, but you want to treat it as numerical value 1, and you have character '2', which has a numerical value of 50 but you want to treat it as a numerical value of 2?

So, you want the following mapping?

Yes? Look at the pattern above, and also consider the fact that you can do arithmetic on characters. Does that give you an idea of how to approach this?

Faisal syed
Ranch Hand

Joined: Mar 25, 2011
Posts: 35

posted

0

I get the fact that I need to have a map.
I realise we can do arithmetic, but the results would be different.

[There is a much simpler way to do such arithmetic, using chars only. ]
Could you give an example please ?

If you had the value x but you actually wanted the value 0, what would you take away from x to get 0.
If you had the value (x + 1) but you actually wanted the value 1, what would you take away from (x + 1) to get 1.
If you had the value (x + 2) but you actually wanted the value 2, what would you take away from (x + 2) to get 2.

Answer those questions and then hopefully the answer to your problem will become clear.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 41051

29

posted

0

Faisal syed wrote: . . . yes. I also meant mapping. . . .

But you said map, which is different from mapping.

Could you give an example please ?

Stuart B has already given you as much information as you really need.

Faisal syed wrote: . . . yes. I also meant mapping. . . .

But you said map, which is different from mapping.

Could you give an example please ?

Stuart B has already given you as much information as you really need.

This may be a case where the OP should step back, take out a pencil and paper, and work it out first. Everyone here seems to easily envision what needs to be done, but I would guess that the reason for this, is that we have done it many many times before. Someone who has never done this should work it out on paper -- even though the maths behind it is ridiculously easy.