Binary decimal converter going wrong in C

0

I'm new to the programming world in C, and yesterday I decided to write a decimal (int) to binary (int) converter. Everything was apparently working, however, some results were giving a unit less, so that example: 44 which should have been 101100, was giving 101099.

PS: I know there are other incredibly easy ways to do a converter, I just wanted to know what the problem with this line of code is.

int binary_conversion(int numb){
    int temp = numb;
    int potf, z;
    int y = 0;
    int pot = 0;
    int x = 0;
    int bin = 0;

    while (x <= numb){
       x = pow(2, pot);
       pot += 1;
    }
    if (pow(2, pot) > numb){potf = pot - 1;}
    else{potf = pot;}

    while (potf >= 0){
        if (pow(2, potf) <= temp){
            z = pow(2, potf);
            y = pow(10, potf);
            bin = bin + y;
            temp = temp - z;
            y = 0;

            }
        potf = potf - 1;
    }
    return bin;

Thank you for your attention as a young man;)

    
asked by anonymous 29.11.2018 / 00:06

0 answers