From d2a5222a382c7765bb40d40ad59e4a9d4822852c Mon Sep 17 00:00:00 2001 From: fdai7801 Date: Fri, 9 Feb 2024 20:13:44 +0100 Subject: [PATCH] kabrel conver_bintodec --- src/main/c/BasicMode.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/c/BasicMode.c b/src/main/c/BasicMode.c index 2c09276..0b1bc48 100644 --- a/src/main/c/BasicMode.c +++ b/src/main/c/BasicMode.c @@ -19,3 +19,16 @@ long long int DecToBin(long long int n) { return bin; } +// convert binary to decimal +long long int BinToDec(long long int n) { + long long int dec = 0, i = 0, rem; + + while (n != 0) { + rem = n % 10; + dec += rem * pow(2, i); + i++; + n /= 10; + } + + return dec; +}