From e504c53d9f38fd1c3063625f7ede00e9e1c0ed91 Mon Sep 17 00:00:00 2001 From: Laurin Date: Wed, 31 Jan 2024 00:02:51 +0100 Subject: [PATCH] added case in binaryStrLen for input 0 length is 1 --- src/conversionOfNumbers/conversionOfNumbers.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c index d614913..9c77555 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.c +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -6,13 +6,17 @@ int binaryStrLen(int input){ int length; + if(input > 0){ for(int x = 0; x < input; x++){ if(pow(2,x) >= input + 1){ length = x; break; } } - return length; + }else if(input == 0){ + length = 1; + } + return length; } char* convertIntToBinaryStr(int input){