diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c new file mode 100644 index 0000000..64dae01 --- /dev/null +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -0,0 +1,19 @@ +#include +#include + +char* convertIntToBinaryStr(int input){ + if(input > 3 || input < 0) return NULL; + int length = 2; + int rest; + char* result = (char*)malloc(sizeof(char) * length + 1); + int index = length - 1; + do{ + rest = input % 2; + input /= 2; + if(rest == 1) result[index] = '1'; + if(rest == 0) result[index] = '0'; + index--; + }while(input != 0); + result[length] = '\0'; + return result; +} \ No newline at end of file