~riderius/cpp-code

cpp-code/decimal2binary.cpp -rw-r--r-- 600 bytes
380d65aariderius digits_analysis.cpp: argv[1] can replace n 11 days ago
                                                                                
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
35
#include <cstdlib>
#include <iostream>

int HHH(unsigned int a, int n);

int main(int argc, char* argv[])
{
    using namespace std;
    unsigned int num;
    if (argc > 1) {
        num = atoi(argv[1]);
    } else
        cin >> num;
    int temp = num, sizeofnumber = 0;
    while (temp > 0) {
        temp /= 2;
        sizeofnumber++;
    }
    for (int count = sizeofnumber; count != 0; count--) {
        cout << HHH(num, count);
    }

    cout << endl;

    return 0;
}

int HHH(unsigned int a, int n)
{
    int d = sizeof(a) * 8;
    a = a << (d - n);
    a = a >> (d - 1);

    return a;
}