From abf4d186ad1b5a3466a1382b61686d3e22f5fbe6 Mon Sep 17 00:00:00 2001 From: Laurin Date: Thu, 1 Feb 2024 12:45:51 +0100 Subject: [PATCH] added if statement to be able to convert negative integers --- src/conversionOfNumbers/conversionOfNumbers.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c index 86af510..1160eab 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.c +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -24,6 +24,10 @@ char* convertIntToBinaryStr(int input){ int length = binaryStrLen(input); int rest; char* result = (char*)malloc(sizeof(char) * length + 1); + if(input < 0){ + result[0] = '-'; + input *= -1; + } result[length] = '\0'; do{ rest = input % 2;