From 08f6485826e376ef4e7d078c825020149f685ec8 Mon Sep 17 00:00:00 2001 From: Laurin Date: Tue, 30 Jan 2024 23:54:26 +0100 Subject: [PATCH] added function to determine binary string length --- src/conversionOfNumbers/conversionOfNumbers.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c index b7ae51b..d614913 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.c +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -1,5 +1,19 @@ #include #include +#include + +#include "conversionOfNumbers.h" + +int binaryStrLen(int input){ + int length; + for(int x = 0; x < input; x++){ + if(pow(2,x) >= input + 1){ + length = x; + break; + } + } + return length; +} char* convertIntToBinaryStr(int input){ if(input > 3 || input < 0) return NULL;