Compare commits

..

No commits in common. "c723b55d05d0d657a75d04f728f9f09874bc3d1c" and "ca14ee97e4d213d41eb4b68d20e7220d7258bc24" have entirely different histories.

2 changed files with 4 additions and 14 deletions

BIN
hallo

Binary file not shown.

View file

@ -1,5 +1,4 @@
#include "hallo-welt.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -10,22 +9,14 @@
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) {
const char *binaerzahl(uint8_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;
}
int32_t bb; // that way we keep the memory lighter
printf(is_negative ? "-" : "");
uint8_t bb;
for (int i = sizeof(bin) * 8 - 1; i >= 0; i--) {
bb = bin >> i;
str[i] = (bb % 2 == 1) ? 1 : 0;
@ -36,9 +27,8 @@ const char *binaerzahl(int32_t bin) {
}
int getint(void) {
uint32_t i;
printf("Geben Sie eine Dezimahlzahl ein: ");
scanf("%u", &i);
uint8_t i;
scanf("%hhu", &i);
return i;
}