1. ## Reading in a number backwards!

Hi,

I have to write a program that will take a binary number (10010111) and then tell it decimal equivalency. But i do not know how to read in a number backwards. I know how to read them in one at a time from left to right but not right to left like i need to.

Any tips or suggestions would be greatly appreciated.

2. One solution is to NOT each bit, thus you will end up with the reverse integer.

The NOT syntex for C++ is this: ~

Kuphryn

3. To get the last number in an int, just do a modulus 10. For example N%10 will give you the last digit for the number N. If you want to keep going, divide N by 10 to chop off the last number, then do modulus again.

4. you could put the number in a char array, use a for loop or two to put the number backwards in another array, and then use atoi() to make it an integer again..

5. Or you could read them into a stack (instead of a string/char*), just push each one in as you get to it. Then pop them out again.
Something like this, where Str is an AnsiString that contains the string just inputed, and S is a stack:
Code:
```  for (int i = 0; i < Str.Length(); i++)
S.Push(Str[i]);

AnsiString Str2;
for (int i = 0; i < Str.Length(); i++)
Str2 = S.Pop(Str[i])```

6. I think the char array idea is simplest, then just read the number as you would a word and process the array elements indivually in a loop