Id: 3007; Nick: Volverin; Timestamp: 2007-12-19 20:07:11; Pasted as: Java
Description: Binär Umrechner
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
class binre
{
	static int [] iFeld_ref = new int [8];
	static int [] iBin_ref = new int [8];
	static int zahl;
	static StdEingabe instream_ref = new StdEingabe();
	static int zahl2 = 0;
	public static void main (String [] args)
	{
 
 
		char eingabe;
 
		System.out.println("Benutzermenue: ");
		System.out.println("c: Zahl Codieren");
		System.out.println("p: Feld ausgeben");
		System.out.println("b: Binaere Zahl einlesen");
		System.out.println("z: Zahl ausgeben");
		System.out.println("n: Feld zurücksetzen");
		System.out.println("x: Programm beenden");
		System.out.print("Geben sie nun ihre gewünschte Operation ein: ");
		eingabe = instream_ref.liesCharacterSkipLine();
 
 
	while	(eingabe != 'x')
	{
		System.out.println("Benutzermenue: ");
		System.out.println("c: Zahl Codieren");
		System.out.println("p: Feld ausgeben");
		System.out.println("n: Feld zurücksetzen");
		System.out.println("b: Binaere Zahl einlesen");
		System.out.println("z: Zahl ausgeben");
		System.out.println("x: Programm beenden");
		System.out.print("Geben sie nun ihre gewünschte Operation ein: ");
		eingabe = instream_ref.liesCharacterSkipLine();
 
 
			switch (eingabe)
			{
				case 'c':
					zahl = instream_ref.liesInteger("Bitte ganze Zahl eingeben: ");
					while ((zahl < 0) && ( zahl > 255))
							zahl = instream_ref.liesInteger("Bitte ganze Zahl eingeben: ");
 
 
					codieren(zahl);
				break;
				case 'p':
					printFeld();
				break;
				case 'n':
					clearFeld();
				break;
				case 'b':
					for (int i=7 ; i >= 0 ; i--)
						iBin_ref[i] = instream_ref.liesInteger();
 
					binaer(iBin_ref);
 				break;
				case 'z':
					System.out.println(zahl2);
				break;
				case 'x':
				;
				break;
				default:
					System.out.println("tuuuut");
			}//endswitch
	}//endwhile
	}//endmain
 
 
 
 
 
 
 
	public static void clearFeld()
	{
		for(int i=0; i< iFeld_ref.length ; i++)
			iFeld_ref [i] = 0;
	}//endclear
 
	public static void printFeld()
	{
		System.out.println("___________________________________");
		System.out.print("|");
 
		for(int i=0 ; i < iFeld_ref.length ; i++)
			System.out.print(" "+iFeld_ref[i]+" |");
 
 
		System.out.println("\n___________________________________");
	}//endprint
 
	public static void codieren(int zahl)
	{
		int i = 0;
		for (int s=128; s>= 1 ; s=s/2 ) 
		{
 
			if(zahl/s==1)
			{
				iFeld_ref[i]=1;
				zahl = zahl - s ;
			}
			else
				iFeld_ref[i]=0;		
 
 
			i++;
 
		}//endfor
	}//endcod
 
 
	public static void binaer(int [] iBin_ref)
	{
		int i = 0 ;
		for (int s=128; s>= 1 ; s=s/2 ) 
		{
 
			if(iBin_ref[i]==1)
				zahl2 = zahl2 +s;			
 
 
			i++;
 
		}//endfor
	}//endbin
 
 
}//endclass
Options: New, Download,
;
Copyright © 2006 by Zyberdog - Some rights reserved. (Browse/Disclaimer/Stats/About) - Highlighted with GeSHi
Nothing to see here.