From fb4ad3c51b11b51a558ee3319254ba0590d0512e Mon Sep 17 00:00:00 2001 From: Laurin Date: Wed, 31 Jan 2024 11:37:58 +0100 Subject: [PATCH] expanded binaryStrLen to determine length in case input is negative --- src/conversionOfNumbers/conversionOfNumbers.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c index fdaf2e8..86af510 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.c +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -5,11 +5,15 @@ #include "conversionOfNumbers.h" int binaryStrLen(int input){ - int length; + int length = 0; if (input == 0) return 1; + if (input < 0){ + input *= -1; + length += 1; + } for (int x = 0; x <= input; x++){ if(pow(2,x) >= input + 1){ - length = x; + length += x; break; } }