Difference between two string.

Apr 3, 2013 at 2:26am
I want to compare two string, and want to see differeince in int form. For example,

1
2
string first_string="0002AE1";
string second_string="0002AE2";


How can i calculate difference between two string? It is obvious difference between above two string is 1/-1, but difference would be 1.
Apr 3, 2013 at 2:28am
Do you want to find the differences between two strings, as the title of your post suggests, or do you want to find the difference between two hex values, as your example suggests?
Apr 3, 2013 at 2:37am
Yes, it would be better if you explain both. Is the result same for the both cases?
Apr 3, 2013 at 2:45am
No, the result is drastically different, and the two things are completely unrelated and on opposite sides of the world from each other.

Example of difference between two strings:
http://github.com/clickteam-plugin/TileMap/commit/a8914aad6def50ba81387339ab77d63ff75aa3b6

Example of difference between two hex numbers:
http://www.wolframalpha.com/input/?i=abs%280x1A+-+0x2B%29
Apr 3, 2013 at 2:56am
I need concrete c++ function which can calculate the difference.
Apr 3, 2013 at 2:57am
You still have not specified which kind of difference you want.
Apr 3, 2013 at 4:20am
Hex value difference. Thnx in advance.
Apr 3, 2013 at 4:38am
1
2
3
int a, b;
std::cin >> std::hex >> a >> b;
std::cout << std::hex << std::abs(b-a) << std::endl;
Working example: http://ideone.com/92eeTP
Apr 3, 2013 at 4:56am
Thnx.
Topic archived. No new replies allowed.