26
This commit is contained in:
parent
5dfa85ffa5
commit
dbe7ecfd43
64
zahlsys.c
Normal file
64
zahlsys.c
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void ausgabeBinaer(int wert) {
|
||||||
|
for (int i = 31; i >= 0; i--) {
|
||||||
|
int bit = (wert >> i) & 1;
|
||||||
|
printf("%d", bit);
|
||||||
|
|
||||||
|
if (i % 8 == 0 && i != 0)
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char eingabe[100] = {"--bo 127 --h"};
|
||||||
|
|
||||||
|
char *pptr, *nptr;
|
||||||
|
int wert;
|
||||||
|
bool b = false, o = false, h = false;
|
||||||
|
do{
|
||||||
|
if(strchr(eingabe, ' ') == NULL)
|
||||||
|
break;
|
||||||
|
nptr = strchr(eingabe, ' ') + 1;
|
||||||
|
pptr = strtok(eingabe, " ");
|
||||||
|
if(pptr[0] == '-' && pptr[1])
|
||||||
|
for (int i = 0; pptr[i]; ++i) {
|
||||||
|
switch (pptr[i]) {
|
||||||
|
case 'b':
|
||||||
|
b = true;
|
||||||
|
break;
|
||||||
|
case 'o':
|
||||||
|
o = true;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
h = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(pptr[0] >= '0' && pptr[0] <= '9')
|
||||||
|
wert = atoi(pptr);
|
||||||
|
strcpy(eingabe, nptr);
|
||||||
|
} while (nptr != NULL);
|
||||||
|
|
||||||
|
printf("Dezimal: %d\n", wert);
|
||||||
|
if(b){
|
||||||
|
printf("Dual: ");
|
||||||
|
ausgabeBinaer(wert);
|
||||||
|
}
|
||||||
|
if(o)
|
||||||
|
printf("Oktal: %o\n", wert);
|
||||||
|
if(h)
|
||||||
|
printf("Hexadezimal: %x\n", wert);
|
||||||
|
if(b == 0 && o == 0 && h == 0){
|
||||||
|
printf("Dual: ");
|
||||||
|
ausgabeBinaer(wert);
|
||||||
|
printf("Oktal: %o\n", wert);
|
||||||
|
printf("Hexadezimal: %x\n", wert);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user