I'm wondering how I can make this function better, more compact, even faster. char* DectoBin(int dec) {    int counter = 0;    int x =0;    while (dec>=x) {        counter++;        x = pow(2, counter);    }    //counter is the # of bits in the converted binary number    char* bin = new char[counter+1];    //+1 for nul byte    int y = counter;    int remainder = 0;    while (counter > 0) {        //% the dec number with the base 2 each time and if remainder>0 then set the bit        remainder = dec % 2;        dec /= 2;        if (counter == y) {            bin[counter] = '\0';        }        if (remainder > 0) {            bin[(counter - 1)] = '1';        }        else {            bin[(counter - 1)] = '0';        }        counter--;    }    return bin; }
Converting decimal integer to binary string
c++;beginner;number systems