Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
What I posted is also the method used to convert a string of digits to an integer if you don't want to use a standard C or C++ convertion function.
Here's aother way:
int c = (a << 3) + (a << 1) + b;
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Edit: Wrong on my part, sorry.
Edit2: Actually... I think I got it.
a << 3 is the same as a * (2 ^ 3)
a >> 3 is the same as a / (2 ^ 3)
Correct me if I'm wrong on this.
Point made: it's obfuscatory and should only be used in the archaic systems, from whence it came, that lack the appropriate machine commands and/or a supporting assembly code library.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
which way is "obfuscatory?"
Well, you are given two ways of doing the same thing:
int c = (a * 10) + b;
int c = (a << 3) + (a << 1) + b;
One of them is straight-forward, one is not. The one that is not is "obfuscatory" (i.e. more complicated and harder to understand for no reason other than to add confusion).Is there a specific command that has not been mentioned yet which is now available that will do the same thing?
You're missing the point. When AD posted this:
int c = (a << 3) + (a << 1) + b;
his point was along the lines of "I've given you a perfectly good solution, yet you ask for another one with no explanation of why the first solution doesn't meet your needs." Then he gave you a solution that does the exact same thing as the first solution, but in an overly-complicated way that no one would ever use instead of the first solution. Why don't you like this?
int c = (a * 10) + b;
I can't think of a command that will do this any better.Not that I have any problem with the way described :)
Why are you asking for a different way then? I'm sure we could come up with even more confusing mathematical formulas that do the exact same thing, but that's probably not what you are looking for. :)
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711