Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

converting decimal to binary in cpp

long long x;
    scanf("%lld", &x);
    long long n = ceil(log2((float)x));
	int bin[n];
    for(int i = n - 1; i >= 0; --i)
    {
        if (x & (1LL << i))
        {
            bin[n - 1 -i] = 1;
        }
        else
        {
            bin[n - 1 - i] = 0;
        }
    }
	for(int i = 0;i < n; ++i) printf("%d", bin[i]);
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #converting #decimal #binary #cpp
ADD COMMENT
Topic
Name
4+2 =