diff --git a/src/decbinary.c b/src/decbinary.c new file mode 100644 index 0000000..fcf1b3b --- /dev/null +++ b/src/decbinary.c @@ -0,0 +1,17 @@ +#include +#include "decbinary.h" + +int decimal_to_binary(int dezimalzahl) { + + + int binärzahl[32]; + int i = 0; + + while (dezimalzahl > 0) { + binärzahl[i++] = dezimalzahl % 2; + dezimalzahl /= 2; + } + + return i; +} + diff --git a/src/decbinary.h b/src/decbinary.h new file mode 100644 index 0000000..7c5b5ff --- /dev/null +++ b/src/decbinary.h @@ -0,0 +1,8 @@ + +#ifndef LINKES_TWIX_DECBINARY_H +#define LINKES_TWIX_DECBINARY_H + +int decimal_to_binary(int dezimalzahl); + + +#endif //LINKES_TWIX_DECBINARY_H diff --git a/src/test_decbinary.c b/src/test_decbinary.c new file mode 100644 index 0000000..747220c --- /dev/null +++ b/src/test_decbinary.c @@ -0,0 +1,18 @@ +#ifdef TEST + +#include "decbinary.h" +#include "unity.h" + +void setUp(void) +{ +} + +void test_decimal_1(void) +{ + int result, expected = 10; + result = decimal_to_binary(2); + + TEST_ASSERT_EQUAL_INT(expected, result); +} + +#endif //TEST \ No newline at end of file