From 69d57301a1f3217c1e042b1c38a59282cfb0c205 Mon Sep 17 00:00:00 2001 From: Laurin Date: Wed, 31 Jan 2024 11:22:50 +0100 Subject: [PATCH] refactoring: moved if statement for input 0 to top --- src/conversionOfNumbers/conversionOfNumbers.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c index 7bf51b2..fdaf2e8 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.c +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -6,16 +6,13 @@ 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; - } + if (input == 0) return 1; + for (int x = 0; x <= input; x++){ + if(pow(2,x) >= input + 1){ + length = x; + break; + } } - }else if(input == 0){ - length = 1; - } return length; }