From 67eeefe058fc247244c2d21efb287c4a90834836 Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Thu, 8 Jul 2021 15:26:44 +0430 Subject: [PATCH 01/45] Added asserts , number length check --- conversions/binary_to_decimal.c | 59 +++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 352d07c16..796d84f6f 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -1,16 +1,22 @@ -/** - * Modified 07/12/2017, Kyler Smith - * - */ - #include +#include +#include +#include +#include -int main() -{ - int remainder, number = 0, decimal_number = 0, temp = 1; - printf("\n Enter any binary number= "); - scanf("%d", &number); +bool is_binary(intmax_t num); +int num_len(intmax_t num); +int main(void) +{ + intmax_t remainder, number = 0, decimal_number = 0, temp = 1; + + int length = num_len(INTMAX_MAX)-1; + printf("\n Enter any binary number , max %d digits: ",length); + scanf("%jd", &number); + assert(num_len(number)<=length); + assert(is_binary(number)); + // Iterate over the number until the end. while (number > 0) { @@ -20,5 +26,36 @@ int main() temp = temp * 2; // used as power of 2 } - printf("%d\n", decimal_number); + printf("%jd\n", decimal_number); + return 0; +} + +bool is_binary(intmax_t num) +{ + int remainder=0; + + while(num>0) + { + remainder=num%10; + if(remainder==0 || remainder==1) + { + num /= 10; + continue; +} + else + return false; + + } + + return true; +} + +int num_len(intmax_t num) +{ + int i; + for(i=0; num>0; i++) + { + num /= 10; + } + return i; } From 0008c6745def650ec30f9e4de4f94cf0e69c1315 Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Thu, 8 Jul 2021 15:47:24 +0430 Subject: [PATCH 02/45] Remove extra empty lines --- conversions/binary_to_decimal.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 796d84f6f..54dbcf71a 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -41,12 +41,10 @@ bool is_binary(intmax_t num) { num /= 10; continue; -} + } else return false; - } - return true; } From 7185941c68857d0261244367c3a141bb34cbef30 Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Thu, 8 Jul 2021 15:52:52 +0430 Subject: [PATCH 03/45] Auto indent --- conversions/binary_to_decimal.c | 57 +++++++++++++++------------------ 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 54dbcf71a..5afd9c05c 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -1,8 +1,8 @@ -#include -#include +#include #include +#include +#include #include -#include bool is_binary(intmax_t num); int num_len(intmax_t num); @@ -10,20 +10,19 @@ int num_len(intmax_t num); int main(void) { intmax_t remainder, number = 0, decimal_number = 0, temp = 1; - - int length = num_len(INTMAX_MAX)-1; - printf("\n Enter any binary number , max %d digits: ",length); + + int length = num_len(INTMAX_MAX) - 1; + printf("\n Enter any binary number , max %d digits: ", length); scanf("%jd", &number); - assert(num_len(number)<=length); + assert(num_len(number) <= length); assert(is_binary(number)); - + // Iterate over the number until the end. - while (number > 0) - { + while (number > 0) { remainder = number % 10; number = number / 10; decimal_number += remainder * temp; - temp = temp * 2; // used as power of 2 + temp = temp * 2; // used as power of 2 } printf("%jd\n", decimal_number); @@ -32,28 +31,24 @@ int main(void) bool is_binary(intmax_t num) { - int remainder=0; - - while(num>0) - { - remainder=num%10; - if(remainder==0 || remainder==1) - { - num /= 10; - continue; - } - else - return false; - } - return true; + int remainder = 0; + + while (num > 0) { + remainder = num % 10; + if (remainder == 0 || remainder == 1) { + num /= 10; + continue; + } else + return false; + } + return true; } int num_len(intmax_t num) { - int i; - for(i=0; num>0; i++) - { - num /= 10; - } - return i; + int i; + for (i = 0; num > 0; i++) { + num /= 10; + } + return i; } From 6e5e5614919e38b9e42df52d91359942cb86b708 Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Thu, 8 Jul 2021 19:16:59 +0430 Subject: [PATCH 04/45] fix: corrected shown hex number. --- conversions/decimal_to_hexa.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/conversions/decimal_to_hexa.c b/conversions/decimal_to_hexa.c index 89de59623..dbf5184c5 100644 --- a/conversions/decimal_to_hexa.c +++ b/conversions/decimal_to_hexa.c @@ -18,6 +18,7 @@ int main() * number****************/ void decimal2Hexadecimal(long num) { + char hex_letters[]="abcdef"; long decimalnum = num; long quotient, remainder; int i, j = 0; @@ -29,17 +30,17 @@ void decimal2Hexadecimal(long num) { remainder = quotient % 16; if (remainder < 10) - hexadecimalnum[j++] = 48 + remainder; + hexadecimalnum[j++] = '0' + remainder; else - hexadecimalnum[j++] = 55 + remainder; + hexadecimalnum[j++] = hex_letters[remainder-10];// 'A' quotient = quotient / 16; } // print the hexadecimal number - - for (i = j; i >= 0; i--) + printf("0x"); + for (i = j-1; i >= 0; i--) { printf("%c", hexadecimalnum[i]); } From 905b80c41ee262ab3c07bc1c1978c3a4232468ff Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Sat, 10 Jul 2021 14:00:57 +0430 Subject: [PATCH 05/45] Changed to recommended typical structure --- conversions/binary_to_decimal.c | 76 +++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 18 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 5afd9c05c..69e386f8f 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -1,34 +1,33 @@ +/** +* A C code to convert a binary number to a decimal one. +* Modified 07/12/2017, Kyler Smith +* Modified 2021 lazy-dude +*/ + #include #include -#include +#include #include #include +/** +* function prototypes +*/ bool is_binary(intmax_t num); int num_len(intmax_t num); +intmax_t binary_decimal(intmax_t num); +void test(void); int main(void) { - intmax_t remainder, number = 0, decimal_number = 0, temp = 1; - - int length = num_len(INTMAX_MAX) - 1; - printf("\n Enter any binary number , max %d digits: ", length); - scanf("%jd", &number); - assert(num_len(number) <= length); - assert(is_binary(number)); - - // Iterate over the number until the end. - while (number > 0) { - remainder = number % 10; - number = number / 10; - decimal_number += remainder * temp; - temp = temp * 2; // used as power of 2 - } - - printf("%jd\n", decimal_number); + test(); + printf("All tests passed.\n"); return 0; } +/** +* is_binary checks whether num is a binary one +*/ bool is_binary(intmax_t num) { int remainder = 0; @@ -44,6 +43,9 @@ bool is_binary(intmax_t num) return true; } +/** +* num_len finds length of an intmax_t num +*/ int num_len(intmax_t num) { int i; @@ -52,3 +54,41 @@ int num_len(intmax_t num) } return i; } + +/** +* binary_decimal function does the actual job of conversion +*/ +intmax_t binary_decimal(intmax_t number) +{ + intmax_t remainder, decimal_number = 0, temp = 1; + + int length = num_len(INTMAX_MAX) - 1; + + assert(number>=0); + assert(num_len(number) <= length); + assert(is_binary(number)); + + // Iterate over the number until the end. + while (number > 0) { + remainder = number % 10; + number = number / 10; + decimal_number += remainder * temp; + temp = temp * 2; // used as power of 2 + } + + return decimal_number; +} + +/** +* some tests using assert +*/ +void test(void) +{ + assert(binary_decimal(0)==0); + assert(binary_decimal(1)==1); + assert(binary_decimal(1110001)==113); + assert(binary_decimal(11111111)==255); + assert(binary_decimal(10000000000)==1024); + assert(binary_decimal(1001110100000100)==40196); +} + From e771021978d265a9fa2efac9b3afd9f592f40a5f Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Wed, 14 Jul 2021 14:41:11 +0430 Subject: [PATCH 06/45] docs: Added some doxygen doc. --- conversions/binary_to_decimal.c | 51 ++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 69e386f8f..752c68b8c 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -1,23 +1,34 @@ -/** -* A C code to convert a binary number to a decimal one. -* Modified 07/12/2017, Kyler Smith -* Modified 2021 lazy-dude -*/ +/** + * @file binary_to_decimal.c + * @brief Converts a binary number to a decimal one. + * @details + * A binary number is input , it is check to be binary + * then number is converted to a decimal number. + * Some tests are added too. + * Modified 07/12/2017 + * Modified 2021 + * @author Kyler Smith + * @author [lazy-dude] (https://github.com/lazy-dude) + */ +// includes #include #include #include #include #include -/** -* function prototypes -*/ +// function prototypes bool is_binary(intmax_t num); int num_len(intmax_t num); intmax_t binary_decimal(intmax_t num); void test(void); +/** + * @brief main function + * @param void + * @returns 0 on exit + */ int main(void) { test(); @@ -26,8 +37,10 @@ int main(void) } /** -* is_binary checks whether num is a binary one -*/ + * @brief is_binary checks whether num is a binary one + * @param num to be checked if it has binary representation + * @return boolean true if num is binary false if not + */ bool is_binary(intmax_t num) { int remainder = 0; @@ -44,8 +57,10 @@ bool is_binary(intmax_t num) } /** -* num_len finds length of an intmax_t num -*/ + * @brief num_len finds length of an intmax_t num + * @param num whose length to be computed + * @return i int length of num + */ int num_len(intmax_t num) { int i; @@ -56,8 +71,10 @@ int num_len(intmax_t num) } /** -* binary_decimal function does the actual job of conversion -*/ + * @brief binary_decimal function does the actual job of conversion + * @param number binary to be converted + * @return decimal_number decimal representation of binary number + */ intmax_t binary_decimal(intmax_t number) { intmax_t remainder, decimal_number = 0, temp = 1; @@ -80,8 +97,10 @@ intmax_t binary_decimal(intmax_t number) } /** -* some tests using assert -*/ + * @brief some tests using assert + * @param void + * @return void + */ void test(void) { assert(binary_decimal(0)==0); From 157f6d11b2497ea4b9bdda060c4e17f7039ab5b5 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sat, 17 Jul 2021 13:21:44 +0430 Subject: [PATCH 07/45] Update conversions/binary_to_decimal.c @file Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 752c68b8c..162b6f658 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -1,5 +1,5 @@ /** - * @file binary_to_decimal.c + * @file * @brief Converts a binary number to a decimal one. * @details * A binary number is input , it is check to be binary @@ -110,4 +110,3 @@ void test(void) assert(binary_decimal(10000000000)==1024); assert(binary_decimal(1001110100000100)==40196); } - From bbb602416b89868c913508283b6190f8862f7c4f Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sat, 17 Jul 2021 13:27:19 +0430 Subject: [PATCH 08/45] Update conversions/binary_to_decimal.c @details Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 162b6f658..becb6b680 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -2,7 +2,7 @@ * @file * @brief Converts a binary number to a decimal one. * @details - * A binary number is input , it is check to be binary + * A binary number is an input, it is checked to be binary * then number is converted to a decimal number. * Some tests are added too. * Modified 07/12/2017 From 82e1f416896deadc680b4874732236b572973311 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sat, 17 Jul 2021 13:29:21 +0430 Subject: [PATCH 09/45] Update conversions/binary_to_decimal.c @details Added ", the" Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index becb6b680..a8e75cb60 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -3,7 +3,7 @@ * @brief Converts a binary number to a decimal one. * @details * A binary number is an input, it is checked to be binary - * then number is converted to a decimal number. + * then, the number is converted to a decimal number. * Some tests are added too. * Modified 07/12/2017 * Modified 2021 From 1e4c3962bdd16cd227a298e8f6201d62ccbcb0ae Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sat, 17 Jul 2021 13:30:03 +0430 Subject: [PATCH 10/45] Update conversions/binary_to_decimal.c Removed a line Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 1 - 1 file changed, 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index a8e75cb60..e271f0b32 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -4,7 +4,6 @@ * @details * A binary number is an input, it is checked to be binary * then, the number is converted to a decimal number. - * Some tests are added too. * Modified 07/12/2017 * Modified 2021 * @author Kyler Smith From 166dc0b3adba7da820bd9577dc0cf8057f10fdc7 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sat, 17 Jul 2021 13:30:59 +0430 Subject: [PATCH 11/45] Update conversions/binary_to_decimal.c Removed: * Modified Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index e271f0b32..b2c2e1f5d 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -4,8 +4,6 @@ * @details * A binary number is an input, it is checked to be binary * then, the number is converted to a decimal number. - * Modified 07/12/2017 - * Modified 2021 * @author Kyler Smith * @author [lazy-dude] (https://github.com/lazy-dude) */ From 57bcffa94437baa23a628e928fc931d2f4546a78 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sat, 17 Jul 2021 13:32:32 +0430 Subject: [PATCH 12/45] Update conversions/binary_to_decimal.c Suggested: main(void) -> main() Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index b2c2e1f5d..68ca19389 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -26,7 +26,7 @@ void test(void); * @param void * @returns 0 on exit */ -int main(void) +int main() { test(); printf("All tests passed.\n"); From 129f4b073bcb371887ce000c20bba1d67bbfbc55 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sat, 17 Jul 2021 13:34:03 +0430 Subject: [PATCH 13/45] Update conversions/binary_to_decimal.c static void test Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 68ca19389..81dd4ffb1 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -98,7 +98,7 @@ intmax_t binary_decimal(intmax_t number) * @param void * @return void */ -void test(void) +static void test() { assert(binary_decimal(0)==0); assert(binary_decimal(1)==1); From 8526600c8c311a53803fd5aaf8cd395d639e373b Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sat, 17 Jul 2021 13:35:38 +0430 Subject: [PATCH 14/45] Update conversions/binary_to_decimal.c test arg doc Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 81dd4ffb1..e33c24bc5 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -94,9 +94,8 @@ intmax_t binary_decimal(intmax_t number) } /** - * @brief some tests using assert - * @param void - * @return void + * @brief Self-test implementations + * @returns void */ static void test() { From 61bed00b3596808979c3c4f18058ce396f64a18c Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sat, 17 Jul 2021 13:36:12 +0430 Subject: [PATCH 15/45] Update conversions/binary_to_decimal.c Comment for test() Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index e33c24bc5..21f06ac03 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -28,7 +28,7 @@ void test(void); */ int main() { - test(); + test(); // run self-test implementations printf("All tests passed.\n"); return 0; } From 4d91c9d09ee105a433ab4d62fd133700b4445c59 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sat, 17 Jul 2021 13:36:47 +0430 Subject: [PATCH 16/45] Update conversions/binary_to_decimal.c Removed prototypes Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 21f06ac03..020676887 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -15,11 +15,6 @@ #include #include -// function prototypes -bool is_binary(intmax_t num); -int num_len(intmax_t num); -intmax_t binary_decimal(intmax_t num); -void test(void); /** * @brief main function From 8defb93778772f20a1e7eab4246713861bf6a5f7 Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Sat, 17 Jul 2021 14:47:05 +0430 Subject: [PATCH 17/45] Followed the two suggestions on code. Explain includes, intmax_t->uintmax_t --- conversions/binary_to_decimal.c | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 020676887..9472da807 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -9,33 +9,19 @@ */ // includes -#include -#include -#include -#include -#include - - -/** - * @brief main function - * @param void - * @returns 0 on exit - */ -int main() -{ - test(); // run self-test implementations - printf("All tests passed.\n"); - return 0; -} +#include /// for assert +#include /// for bool +#include /// for uintmax_t +#include /// for IO operations /** * @brief is_binary checks whether num is a binary one * @param num to be checked if it has binary representation * @return boolean true if num is binary false if not */ -bool is_binary(intmax_t num) +bool is_binary(uintmax_t num) { - int remainder = 0; + unsigned remainder = 0; while (num > 0) { remainder = num % 10; @@ -49,11 +35,11 @@ bool is_binary(intmax_t num) } /** - * @brief num_len finds length of an intmax_t num + * @brief num_len finds length of an uintmax_t num * @param num whose length to be computed * @return i int length of num */ -int num_len(intmax_t num) +int num_len(uintmax_t num) { int i; for (i = 0; num > 0; i++) { @@ -67,13 +53,13 @@ int num_len(intmax_t num) * @param number binary to be converted * @return decimal_number decimal representation of binary number */ -intmax_t binary_decimal(intmax_t number) +uintmax_t binary_decimal(uintmax_t number) { - intmax_t remainder, decimal_number = 0, temp = 1; + unsigned remainder; + uintmax_t decimal_number = 0, temp = 1; - int length = num_len(INTMAX_MAX) - 1; + int length = num_len(UINTMAX_MAX) - 1; - assert(number>=0); assert(num_len(number) <= length); assert(is_binary(number)); @@ -101,3 +87,17 @@ static void test() assert(binary_decimal(10000000000)==1024); assert(binary_decimal(1001110100000100)==40196); } + +/** + * @brief main function + * @param void + * @returns 0 on exit + */ +int main() +{ + test(); // run self-test implementations + printf("All tests passed.\n"); + return 0; +} + + From 639773329cace2c2a5bca2ee0004f9aa293ef3e2 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sun, 18 Jul 2021 13:30:29 +0430 Subject: [PATCH 18/45] Update conversions/binary_to_decimal.c corrected @return Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 9472da807..d8a961fbe 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -37,7 +37,7 @@ bool is_binary(uintmax_t num) /** * @brief num_len finds length of an uintmax_t num * @param num whose length to be computed - * @return i int length of num + * @return the length of the number */ int num_len(uintmax_t num) { @@ -100,4 +100,3 @@ int main() return 0; } - From 45e4effd3aceb813420ce3165c88d972391e1757 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sun, 18 Jul 2021 13:31:25 +0430 Subject: [PATCH 19/45] Update conversions/binary_to_decimal.c Removed space Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index d8a961fbe..ca0d485f4 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -5,7 +5,7 @@ * A binary number is an input, it is checked to be binary * then, the number is converted to a decimal number. * @author Kyler Smith - * @author [lazy-dude] (https://github.com/lazy-dude) + * @author [lazy-dude](https://github.com/lazy-dude) */ // includes @@ -99,4 +99,3 @@ int main() printf("All tests passed.\n"); return 0; } - From 65536403b52332d904b3992101b1d351ceb7bc87 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sun, 18 Jul 2021 13:32:06 +0430 Subject: [PATCH 20/45] Update conversions/binary_to_decimal.c Removed // includes Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index ca0d485f4..2e8c8099d 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -8,8 +8,7 @@ * @author [lazy-dude](https://github.com/lazy-dude) */ -// includes -#include /// for assert +#include /// for assert #include /// for bool #include /// for uintmax_t #include /// for IO operations From 09df4a4f7da66cdf64cf02c2ac367010e44e4759 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Sun, 18 Jul 2021 13:32:38 +0430 Subject: [PATCH 21/45] Update conversions/binary_to_decimal.c Added i=0; Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 2e8c8099d..19a94f7c0 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -40,7 +40,7 @@ bool is_binary(uintmax_t num) */ int num_len(uintmax_t num) { - int i; + int i = 0; for (i = 0; num > 0; i++) { num /= 10; } From 63cf38caa98923875119e0aad20047849e554f79 Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Sun, 18 Jul 2021 13:55:25 +0430 Subject: [PATCH 22/45] Changes of some types. --- conversions/binary_to_decimal.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 19a94f7c0..8a2d0c225 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -38,13 +38,13 @@ bool is_binary(uintmax_t num) * @param num whose length to be computed * @return the length of the number */ -int num_len(uintmax_t num) +uint16_t num_len(uintmax_t num) { - int i = 0; - for (i = 0; num > 0; i++) { + uint16_t len = 0; + for (len = 0; num > 0; len++) { num /= 10; } - return i; + return len; } /** @@ -54,10 +54,11 @@ int num_len(uintmax_t num) */ uintmax_t binary_decimal(uintmax_t number) { - unsigned remainder; - uintmax_t decimal_number = 0, temp = 1; + uint8_t remainder; + uintmax_t decimal_number = 0; + uint32_t temp = 1; - int length = num_len(UINTMAX_MAX) - 1; + uint16_t length = num_len(UINTMAX_MAX) - 1; assert(num_len(number) <= length); assert(is_binary(number)); From e078df2969c166cd1c3db9affae51132c05755fa Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Wed, 21 Jul 2021 15:25:06 +0430 Subject: [PATCH 23/45] Update conversions/binary_to_decimal.c Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 8a2d0c225..6e0dda028 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -4,7 +4,7 @@ * @details * A binary number is an input, it is checked to be binary * then, the number is converted to a decimal number. - * @author Kyler Smith + * @author [Kyler Smith](https://github.com/KylerSmith) * @author [lazy-dude](https://github.com/lazy-dude) */ From 0b199fb11be37a2a8e0e3f6f7061e468f8bea555 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Wed, 21 Jul 2021 15:25:48 +0430 Subject: [PATCH 24/45] Update conversions/binary_to_decimal.c Spacing /// Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 6e0dda028..e5c9ffe70 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -8,10 +8,10 @@ * @author [lazy-dude](https://github.com/lazy-dude) */ -#include /// for assert -#include /// for bool -#include /// for uintmax_t -#include /// for IO operations +#include /// for assert +#include /// for bool +#include /// for uintmax_t +#include /// for IO operations /** * @brief is_binary checks whether num is a binary one From f66cd1b3167d0b7600e22b2a63a72c29b16f1025 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Wed, 21 Jul 2021 15:27:18 +0430 Subject: [PATCH 25/45] Update conversions/binary_to_decimal.c Corrected @brief Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index e5c9ffe70..89ec2c951 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -14,7 +14,7 @@ #include /// for IO operations /** - * @brief is_binary checks whether num is a binary one + * @brief checks whether the number is binary * @param num to be checked if it has binary representation * @return boolean true if num is binary false if not */ From fd82d9e5d0401f7b26349b9c97a5a3a0f8881786 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Wed, 21 Jul 2021 15:28:20 +0430 Subject: [PATCH 26/45] Update conversions/binary_to_decimal.c two @returns Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 89ec2c951..86a8f0f25 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -16,7 +16,8 @@ /** * @brief checks whether the number is binary * @param num to be checked if it has binary representation - * @return boolean true if num is binary false if not + * @returns true if the number IS binary + * @returns false if the number is NOT binary */ bool is_binary(uintmax_t num) { From ebf83bb359b018d4781198360f4aef931c20e692 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Wed, 21 Jul 2021 15:29:39 +0430 Subject: [PATCH 27/45] Update conversions/binary_to_decimal.c Improved @brief Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 86a8f0f25..d7bd940ff 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -35,7 +35,7 @@ bool is_binary(uintmax_t num) } /** - * @brief num_len finds length of an uintmax_t num + * @brief finds the length of an `uintmax_t` number * @param num whose length to be computed * @return the length of the number */ From 63a9a165dcdc6566a88be7956aebaf14f4df54f7 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Wed, 21 Jul 2021 15:30:15 +0430 Subject: [PATCH 28/45] Update conversions/binary_to_decimal.c Removed printf Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 1 - 1 file changed, 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index d7bd940ff..5f9d82f03 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -97,6 +97,5 @@ static void test() int main() { test(); // run self-test implementations - printf("All tests passed.\n"); return 0; } From a2ca6608d47cb330b69cd4e7878c15c7fe5e2b3a Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Wed, 21 Jul 2021 15:30:48 +0430 Subject: [PATCH 29/45] Update conversions/binary_to_decimal.c Added printf Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 5f9d82f03..c2313d072 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -87,6 +87,8 @@ static void test() assert(binary_decimal(11111111)==255); assert(binary_decimal(10000000000)==1024); assert(binary_decimal(1001110100000100)==40196); + + printf("All tests have passed!\n"); } /** From 81ab47cbad765757c513bce907a571f1c470c122 Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Wed, 21 Jul 2021 15:39:14 +0430 Subject: [PATCH 30/45] Considered some suggestions --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index c2313d072..4661cb094 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -88,7 +88,7 @@ static void test() assert(binary_decimal(10000000000)==1024); assert(binary_decimal(1001110100000100)==40196); - printf("All tests have passed!\n"); + printf("All tests have passed!\n"); } /** From 0f96de59a6c7bc31a3dabc701aa1bfaff0f64c28 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Thu, 22 Jul 2021 14:39:12 +0430 Subject: [PATCH 31/45] Update conversions/binary_to_decimal.c @brief Change Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 4661cb094..c4304fde2 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -49,7 +49,7 @@ uint16_t num_len(uintmax_t num) } /** - * @brief binary_decimal function does the actual job of conversion + * @brief The `binary_decimal` function does the actual job of conversion * @param number binary to be converted * @return decimal_number decimal representation of binary number */ From 254cabfeef111bfea548aef71c1182d97755d087 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Thu, 22 Jul 2021 14:39:59 +0430 Subject: [PATCH 32/45] Update conversions/binary_to_decimal.c @param added 'the ' Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index c4304fde2..6f9be2456 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -50,7 +50,7 @@ uint16_t num_len(uintmax_t num) /** * @brief The `binary_decimal` function does the actual job of conversion - * @param number binary to be converted + * @param the number binary to be converted * @return decimal_number decimal representation of binary number */ uintmax_t binary_decimal(uintmax_t number) From 8c1b54805657f83d9d3a9c8e1e47d3ae002bac49 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Thu, 22 Jul 2021 14:40:32 +0430 Subject: [PATCH 33/45] Update conversions/binary_to_decimal.c @return added 'a ' Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 6f9be2456..9647c65ee 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -51,7 +51,7 @@ uint16_t num_len(uintmax_t num) /** * @brief The `binary_decimal` function does the actual job of conversion * @param the number binary to be converted - * @return decimal_number decimal representation of binary number + * @return decimal_number decimal representation of a binary number */ uintmax_t binary_decimal(uintmax_t number) { From 8632490e0a5f0c534c59d4a4fed960094f65eaf0 Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Thu, 22 Jul 2021 15:19:24 +0430 Subject: [PATCH 34/45] Added link for explaination. --- conversions/binary_to_decimal.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 9647c65ee..bc099eef1 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -4,6 +4,7 @@ * @details * A binary number is an input, it is checked to be binary * then, the number is converted to a decimal number. + * [Binary to decimal](https://byjus.com/binary-to-decimal-formula/) * @author [Kyler Smith](https://github.com/KylerSmith) * @author [lazy-dude](https://github.com/lazy-dude) */ @@ -59,20 +60,20 @@ uintmax_t binary_decimal(uintmax_t number) uintmax_t decimal_number = 0; uint32_t temp = 1; - uint16_t length = num_len(UINTMAX_MAX) - 1; + uint16_t length = num_len(UINTMAX_MAX) - 1; - assert(num_len(number) <= length); - assert(is_binary(number)); + assert(num_len(number) <= length); + assert(is_binary(number)); - // Iterate over the number until the end. - while (number > 0) { - remainder = number % 10; - number = number / 10; - decimal_number += remainder * temp; - temp = temp * 2; // used as power of 2 - } + // Iterate over the number until the end. + while (number > 0) { + remainder = number % 10; + number = number / 10; + decimal_number += remainder * temp; + temp = temp * 2; // used as power of 2 + } - return decimal_number; + return decimal_number; } /** From 8fa92c500956bb4fbf2cfbafbdee02a479fc0dbd Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Fri, 23 Jul 2021 14:03:39 +0430 Subject: [PATCH 35/45] Update conversions/binary_to_decimal.c Link removed Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 1 - 1 file changed, 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index bc099eef1..c9571b22d 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -4,7 +4,6 @@ * @details * A binary number is an input, it is checked to be binary * then, the number is converted to a decimal number. - * [Binary to decimal](https://byjus.com/binary-to-decimal-formula/) * @author [Kyler Smith](https://github.com/KylerSmith) * @author [lazy-dude](https://github.com/lazy-dude) */ From 4ab5a258655cdaa3edf9a30f5b7c383254b42ae0 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Fri, 23 Jul 2021 14:04:40 +0430 Subject: [PATCH 36/45] Update conversions/binary_to_decimal.c @param added 'the number' Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index c9571b22d..439e4e970 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -15,7 +15,7 @@ /** * @brief checks whether the number is binary - * @param num to be checked if it has binary representation + * @param num the number to be checked if it has binary representation * @returns true if the number IS binary * @returns false if the number is NOT binary */ From da7387885afc456497e3e152ce0fb00f68dc708a Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Fri, 23 Jul 2021 14:05:22 +0430 Subject: [PATCH 37/45] Update conversions/binary_to_decimal.c @brief link added Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 439e4e970..3613ddc85 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -1,6 +1,6 @@ /** * @file - * @brief Converts a binary number to a decimal one. + * @brief Converts a [binary to a decimal](https://byjus.com/binary-to-decimal-formula/) number implementation. * @details * A binary number is an input, it is checked to be binary * then, the number is converted to a decimal number. From 71c17eed722d4cc881635c200376c5463f9e6f1e Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Fri, 23 Jul 2021 14:38:54 +0430 Subject: [PATCH 38/45] return -> returns --- conversions/binary_to_decimal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 3613ddc85..519ecdc46 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -37,7 +37,7 @@ bool is_binary(uintmax_t num) /** * @brief finds the length of an `uintmax_t` number * @param num whose length to be computed - * @return the length of the number + * @returns the length of the number */ uint16_t num_len(uintmax_t num) { @@ -51,7 +51,7 @@ uint16_t num_len(uintmax_t num) /** * @brief The `binary_decimal` function does the actual job of conversion * @param the number binary to be converted - * @return decimal_number decimal representation of a binary number + * @returns decimal_number decimal representation of a binary number */ uintmax_t binary_decimal(uintmax_t number) { From c3433f73f0a01287d631f35ecc53b5ecdeaf07f0 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Mon, 26 Jul 2021 11:31:53 +0430 Subject: [PATCH 39/45] Update conversions/binary_to_decimal.c Removed a word Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 519ecdc46..8e0688e88 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -1,6 +1,6 @@ /** * @file - * @brief Converts a [binary to a decimal](https://byjus.com/binary-to-decimal-formula/) number implementation. + * @brief Converts a [binary to a decimal](https://byjus.com/binary-to-decimal-formula/) number. * @details * A binary number is an input, it is checked to be binary * then, the number is converted to a decimal number. From 53e719b61d0952bbe43479e4e725f1393eb1a4ed Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Mon, 26 Jul 2021 11:32:38 +0430 Subject: [PATCH 40/45] Update conversions/binary_to_decimal.c it to that Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 8e0688e88..30900c396 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -2,7 +2,7 @@ * @file * @brief Converts a [binary to a decimal](https://byjus.com/binary-to-decimal-formula/) number. * @details - * A binary number is an input, it is checked to be binary + * A binary number is an input that is checked to be binary * then, the number is converted to a decimal number. * @author [Kyler Smith](https://github.com/KylerSmith) * @author [lazy-dude](https://github.com/lazy-dude) From af4b346488105cf2f76460a32fd0d11a5f2eec87 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Mon, 26 Jul 2021 11:33:14 +0430 Subject: [PATCH 41/45] Update conversions/binary_to_decimal.c Added number Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 30900c396..f1f627c39 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -50,7 +50,7 @@ uint16_t num_len(uintmax_t num) /** * @brief The `binary_decimal` function does the actual job of conversion - * @param the number binary to be converted + * @param number the number binary to be converted * @returns decimal_number decimal representation of a binary number */ uintmax_t binary_decimal(uintmax_t number) From aa8e55b10f88038e5b5957e227e2ae62ec74b8ec Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Mon, 26 Jul 2021 11:33:47 +0430 Subject: [PATCH 42/45] Update conversions/binary_to_decimal.c printf indent Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index f1f627c39..366d33628 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -88,7 +88,7 @@ static void test() assert(binary_decimal(10000000000)==1024); assert(binary_decimal(1001110100000100)==40196); - printf("All tests have passed!\n"); + printf("All tests have passed!\n"); } /** From 0d61a4ab470fd9aeee773bb231715fd14f053c63 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Tue, 27 Jul 2021 16:26:18 +0430 Subject: [PATCH 43/45] Update conversions/binary_to_decimal.c Added 'number' Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 366d33628..d7d73217f 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -1,6 +1,6 @@ /** * @file - * @brief Converts a [binary to a decimal](https://byjus.com/binary-to-decimal-formula/) number. + * @brief Converts a [binary number to a decimal](https://byjus.com/binary-to-decimal-formula/) number. * @details * A binary number is an input that is checked to be binary * then, the number is converted to a decimal number. From 82fb3ae7056833f0100136f303ae9727b61ca865 Mon Sep 17 00:00:00 2001 From: lazy-dude <76253503+lazy-dude@users.noreply.github.com> Date: Tue, 27 Jul 2021 16:26:44 +0430 Subject: [PATCH 44/45] Update conversions/binary_to_decimal.c Added `` Co-authored-by: David Leal --- conversions/binary_to_decimal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index d7d73217f..7bb98c98e 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -16,8 +16,8 @@ /** * @brief checks whether the number is binary * @param num the number to be checked if it has binary representation - * @returns true if the number IS binary - * @returns false if the number is NOT binary + * @returns `true` if the number IS binary + * @returns `false` if the number is NOT binary */ bool is_binary(uintmax_t num) { From 96123254d39669ae31e5d88e844aced1dcdcc08c Mon Sep 17 00:00:00 2001 From: lazy-dude Date: Tue, 27 Jul 2021 16:41:18 +0430 Subject: [PATCH 45/45] Added description --- conversions/binary_to_decimal.c | 1 + 1 file changed, 1 insertion(+) diff --git a/conversions/binary_to_decimal.c b/conversions/binary_to_decimal.c index 7bb98c98e..7431995a7 100644 --- a/conversions/binary_to_decimal.c +++ b/conversions/binary_to_decimal.c @@ -25,6 +25,7 @@ bool is_binary(uintmax_t num) while (num > 0) { remainder = num % 10; + // make sure each digit is 0 or 1 if (remainder == 0 || remainder == 1) { num /= 10; continue;