-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.c
More file actions
56 lines (42 loc) · 906 Bytes
/
dev.c
File metadata and controls
56 lines (42 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
char vBuf[128];
char* crtBitStr(int x)
{
// printf("%d\n",sizeof(x));
// dualzahl erstellen
int rest,j,temp;
temp=x;
int i=(sizeof(int)*8+1);
//länge der Dualzahl von 32 oder 64bit system abhnängig
static char dual[sizeof(int)*8+1];
while (i!=0)
{
//modulooperation
rest=temp%2;
temp=temp/2;
i--;
//zählt zurück bis 0
dual[i]= rest + '0';
//gibt dualzahl an hauptprogramm zurück
}
//ausgabe formatieren
//0000 0000|0000 0000|0000 0000|
return dual;
}
/*har* ctrHexStr(int x)
{
}
*/
int main()
{
int dez=0;
char *dualvar;//[sizeof(int)*8+1];
printf("Eingabe einer int-Zahl: "); fgets(vBuf,128,stdin);
dez=atoi(vBuf);
dualvar=crtBitStr(dez);
printf("Bin: %s\n",dualvar);
printf("Hex: 0x%x\n",dez);
printf("\n");
return 0;
}