Thread Dezimalzahl in Dualzahl umwandeln (37 answers)
Opened by SirLant at 2003-09-08 18:55

SirLant
 2003-09-08 18:55
#11015 #11015
User since
2003-08-04
516 Artikel
BenutzerIn
[default_avatar]
Habe aus meinem Buch folgendes kleines Progrämmchen:

Code: (dl )
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
57
58
59
60
#include <stdio.h>

/*Prototypen*/
short pruefen (short);
short dezbin (short);

int main () {

short dec;
short eingabe = 1;

while (eingabe) {

printf ("Geben Sie eine Zahl ein (0-255):");
scanf ("%d", &dec);

eingabe = pruefen (dec);
if (eingabe == 1) {

printf ("Fehler bei der Eingabe!\n");

}//if
else {

dezbin (dec);

}

}//while

return (0);

}//main

//Prüft die Eingabe
short pruefen (short input) {

if ((input >= 0) && (input <256)) return (0);
else return (1);

}//pruefen

//Wandelt eine Dezimalzahl in eine Dualzahl um
short dezbin (short zahl) {

short x,i;

for (i = 7; i >= 0; i--) { /* Absichtlich ein wenig Umständlich */

x = zahl / (1 << i);
x = zahl - x * (1 << i);

printf ("%d",x);

}//for

return (0);

}//dezbin


Kann mir jemand erklären, was die Funktion dezbin macht?
Verstehe den Vorgang dort nicht und im Buch wird darauf nicht
näher eingegangen :(\n\n

<!--EDIT|SirLant|1063227448-->
--Programming today is a race between Software Enginers striving to build bigger and better idiot-proof Programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning!

View full thread Dezimalzahl in Dualzahl umwandeln