I
I
Ilya2014-11-23 22:53:45
C++ / C#
Ilya, 2014-11-23 22:53:45

Translation function from 10 to 2 in C?

Good day. Maybe someone in the snippets has the function of converting from 10th to 2nd number system in C, please share.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
ExeTwezz, 2014-11-23
@ExeTwezz

int dec2bin(int num)
{
    int bin = 0, k = 1;

    while (num)
    {
        bin += (num % 2) * k;
        k *= 10;
        num /= 2;
    }

    return bin;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question