Autor Beitrag
Windoof
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

Windows 95/98 SE/NT4.0 WS/2000 Professional/XP Home & Professional, SuSE Linux 7.0/9.0 Professional, OpenBSD
Dev-C++ 4.9.9.0, Borland C++ Builder 3 Personal/5 Professional/6 Enterprise, Borland Delphi 6 Enterprise/7 Enterprise
BeitragVerfasst: Do 03.03.05 11:41 
Hallo Leute, ich bin ja C++'ler und habe eine Frage: Ich habe folgende Funktion in C++:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
String IntToBin(int zahl,int stellen=-1)
{
  int i;
  String b;
  for(i=1;i<zahl;i*=2);
  for(;i>0;i/=2)
    b=String(char('0'+(zahl&i)))+b;
  for(i=b.Length();i<=stellen;++i)
    b='0'+b;
  i.~int();
  return b;
}
Nun wollte ich mal fragen, wie dasin Delphi so geht? Soweit bin ich bereits:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function IntToBin(zahl,stellen:Integer):String;
var i:Integer;
begin
    i:=1;
    while i<zahl do
        i:=i*2;
    while i>0 do
    begin
        Result:=(('0'+(zahl&i))as String)+Result; //Wie muss diese Zeile aussehen? Da gibts nämlich Probleme: & ist kein gültiges Zeichen
        i:=i/2;
    end;
    for i:=Length(Result) to stellen do
        Result:='0'+Result;
end;

_________________
C++ Club - Tomorrow we'll be your favourite!
*gleichnamige Website international*
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Do 03.03.05 11:59 
versuche es mal mit AND

und inttostr(i) (=itoa) statt "as string"
Windoof Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

Windows 95/98 SE/NT4.0 WS/2000 Professional/XP Home & Professional, SuSE Linux 7.0/9.0 Professional, OpenBSD
Dev-C++ 4.9.9.0, Borland C++ Builder 3 Personal/5 Professional/6 Enterprise, Borland Delphi 6 Enterprise/7 Enterprise
BeitragVerfasst: Do 03.03.05 12:33 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
function IntToBin(zahl,stellen:Integer):String;
var i:Integer;
b:String;
begin
    i:=1;
    while i<zahl do
        i:=i*2;
    while i>0 do
    begin
        b:=String(Char(Integer('0')+Integer(zahl and i)))+b;
        i:=Round(i/2);
    end;
    for i:=Length(b) to stellen-1 do
        b:='0'+b;
    Result:=b;
end;
Ist es nicht. Ziel derSacheist es einfach den Binärweet einer Dezimalzahl zu ermitteln, d.h. ich will mir eine Liste aller ASCII-Zeichen machen mit folgenden Spalten: Zeichen, Dezimal, Hexadezimal und Binär. and ist es nicht, ich denke eher an einem anderen schlüsselwort alá mod... nur nicht mod sondern halt bitweises AND, kein logisches AND. Wie heißt das BitweiseAND in Delphi?

_________________
C++ Club - Tomorrow we'll be your favourite!
*gleichnamige Website international*
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8535
Erhaltene Danke: 473

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 03.03.05 12:39 
Doch, AND ist das, was du suchst:
ausblenden Delphi-Quelltext
1:
2:
bool1 AND bool2 // Boolsches AND
int1 AND int2 // Bitweises AND

_________________
We are, we were and will not be.
Windoof Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

Windows 95/98 SE/NT4.0 WS/2000 Professional/XP Home & Professional, SuSE Linux 7.0/9.0 Professional, OpenBSD
Dev-C++ 4.9.9.0, Borland C++ Builder 3 Personal/5 Professional/6 Enterprise, Borland Delphi 6 Enterprise/7 Enterprise
BeitragVerfasst: Do 03.03.05 12:52 
*omg* sorry leute... ich hab zwar ohne and gearbeitet, weil das bei mir wirklich nicht geklappt hat, aber ichhatte noch einen adneren fehler drin, hier die funktion, wie sie funktioniert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
function IntToBin(zahl,stellen:Integer):String;
var i:Integer;
b:String;
begin
    i:=1;
    while i<zahl do
        i:=i*2;
    if i>zahl then
        i:=Round(i/2);
    while i>0 do
    begin
        inc(zahl,-i);
        b:=b+String(Char(Integer('0')+Integer(zahl>-1)));
        if zahl<0 then
            inc(zahl,i);
        i:=Round(i/2);
    end;
    while stellen>Length(b) do
        b:='0'+b;
    Result:=b;
end;

_________________
C++ Club - Tomorrow we'll be your favourite!
*gleichnamige Website international*
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Do 03.03.05 13:18 
Oder so...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function IntToBin(zahl,ziffern : integer) : string;
begin
 SetLength(Result,ziffern);
 while (ziffern>0do
 begin
  Result[ziffern]:=IntToStr(zahl and 1)[1];
  zahl := zahl shr 1;
  dec(ziffern);
 end;
end;
OneOfTen
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 03.03.05 14:48 
fängste schon wieder mit kürzeren oder besseren Funktionen an, Spaceguide? :wink:
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Do 03.03.05 14:51 
durchaus berechtigt, die funktion von windoof ist ja furchtbar (naja so denkt halt wohl ein c-coder)
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Do 03.03.05 14:58 
Die Funktion macht aber nicht dasselbe. Wenn du weniger Stellen angibst als benötigt, um die Zahl darzustellen, bekommst du Probleme.
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Do 03.03.05 17:25 
Da bekomm ich keine Probleme, sondern die niederwertigen Bits.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Do 03.03.05 17:35 
Aber Kompatibilitätsprobleme, wenn du seine Funktion durch deine ersetzst...
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Do 03.03.05 18:55 
Also meine Funktion verhält sich eigentlich genauso wie die von Windoof.