Browse Source

added if statement to be able to convert negative integers

remotes/origin/conversionOfNumbers
Laurin 11 months ago
parent
commit
abf4d186ad
  1. 4
      src/conversionOfNumbers/conversionOfNumbers.c

4
src/conversionOfNumbers/conversionOfNumbers.c

@ -24,6 +24,10 @@ char* convertIntToBinaryStr(int input){
int length = binaryStrLen(input); int length = binaryStrLen(input);
int rest; int rest;
char* result = (char*)malloc(sizeof(char) * length + 1); char* result = (char*)malloc(sizeof(char) * length + 1);
if(input < 0){
result[0] = '-';
input *= -1;
}
result[length] = '\0'; result[length] = '\0';
do{ do{
rest = input % 2; rest = input % 2;

Loading…
Cancel
Save