Is it Possible to Reverse the Direction of Variables?

The title may not have been the best but I'll try to clarify. I'm making a program that converts Base10 (Decimal) to Base2 (Binary) and as you may or may not know that when you convert Base10 you must reverse the numbers in which you converted the numbers. I can easily display the numbers but wonder if there is a fairly simple way of displaying them in reverse (preferably without the use of arrays - just a preference of mine). Here is the code I have created in case you'd like more clarification.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>

int main()
{
    using namespace std;
    
    int base10 = 0, base10copy = 0, base10copy2 = 0;
    bool first = true;
    
    cout << "Base 10: ";
    cin >> base10;
    
    base10copy = base10;
    base10copy2 = base10;
    
    while (base10copy != 1)
    {
          if (first == true)
          {
              cout << "Base2: " << (base10%2) << endl;
              first = false;
          }
          else
          {            
          base10copy = (base10copy/2);
          base10 = (base10copy%2);
          cout << "Base2: "  << base10 << endl; 
          }
    }    

    char response;
    cin >> response;
    return 0;
}


Thanks in advance.
Get the bits in the reverse order.

if n & ( 1 << 31 ) is true (non-zero), then the MSB is 1 otherwise it is 0.
Topic archived. No new replies allowed.