Browse Source

Merge branch 'decbinary' into 'master'

Decbinary

See merge request fdai7848/Linkes-Twix!13
master
fdai7851 11 months ago
parent
commit
c26c0c3fc2
  1. 17
      src/decbinary.c
  2. 8
      src/decbinary.h
  3. 18
      src/test_decbinary.c

17
src/decbinary.c

@ -0,0 +1,17 @@
#include <stdio.h>
#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;
}

8
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

18
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
Loading…
Cancel
Save