From a7218c6a732cdbd73a6397ddbf8260a0d9a7bf94 Mon Sep 17 00:00:00 2001 From: Laurin Date: Fri, 2 Feb 2024 09:21:59 +0100 Subject: [PATCH] implemented prototype function to convert binary strings of 1s into decimal --- src/conversionOfNumbers/conversionOfNumbers.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c index 1160eab..4c97fbf 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.c +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -37,4 +37,16 @@ char* convertIntToBinaryStr(int input){ length--; }while(input != 0); return result; +} + +unsigned int convertBinaryStrToInt(char* input){ + unsigned int result = 0; + int x = 0; + while(input[x] != '\0'){ + if(input[x] == '1'){ + result += 1 * pow(2, x); + } + x++; + } + return result; } \ No newline at end of file