37 lines
817 B
C
37 lines
817 B
C
#include "hallo-welt.h"
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#ifndef HALLO
|
|
#define HALLO "Hallo Welt"
|
|
#endif
|
|
|
|
void hallo_welt(void) { printf(HALLO); }
|
|
|
|
int zweierkomplement(int32_t i) { return ~i + 1; }
|
|
|
|
// use more then one int type
|
|
const char *binaerzahl(int32_t bin) {
|
|
char *str = malloc(sizeof(bin) * 8 +
|
|
1); // Allocate 8 bits for actual data and 1 Bit for the \0
|
|
// sign indicating the end of the string
|
|
bool is_negative;
|
|
if (!str)
|
|
return NULL;
|
|
if (bin < 0) {
|
|
bin = zweierkomplement(bin);
|
|
is_negative = true;
|
|
return str;
|
|
}
|
|
}
|
|
|
|
int getint(void) {
|
|
uint32_t i;
|
|
printf("Geben Sie eine Dezimahlzahl ein: ");
|
|
scanf("%u", &i);
|
|
return i;
|
|
}
|
|
|
|
int main(void) { printf("%s", binaerzahl(getint())); }
|