Remove leading zeros after decimal conversion to binary (and can only be shifted by & | ^)

sources of topics and their own ideas

for example: 8000000000000000000000000000000001000

       1000   & | ^ -sharp-sharp-sharp 

related codes


-sharpinclude <iostream>
using namespace std;
{
        int y;
        cin >> y;
    for (int i = sizeof(y) * 8 - 1; i >= 0; i--)
        {
            bool status = (y >> i) & 1;
            cout << status;
        }cout << endl;
bool start = false;
        for (int i = sizeof(y) * 8 - 1; i >= 0; i--)
        {
            bool status = (y >> i) & 1;
            if (status && !start) 
                start = true;
            if (start) 
                cout << status;
        }
    }

what result do you expect? What is the error message actually seen?

the zero after 1 is gone and there is an extra zero

.
CPP c
Feb.15,2022

first find the first 1, remember the position, and then go from this position to the end, move the corresponding position by 1 to the left each time, and decide whether the output is 0 or 1

.
Menu