Einzelnen Beitrag anzeigen

Benutzerbild von p80286
p80286

Registriert seit: 28. Apr 2008
Ort: Stolberg (Rhl)
6.659 Beiträge
 
FreePascal / Lazarus
 
#7

Re: Umrechnen von Zahlensystem

  Alt 9. Nov 2009, 16:43
Zitat von Ghose:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Math, StrUtils;

type
  TForm1 = class(TForm)
    Eingaberadiogroup: TRadioGroup;
    Ausgaberadiogroup: TRadioGroup;
    Eingabeedit: TEdit;
    Eingabe: TLabel;
    Ausgabe: TLabel;
    Berechnungsbutton: TButton;
    Ausgabeedit: TEdit;
    procedure BerechnungsbuttonClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
      { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  x: integer;
  BinArray: Array [1..16] of Integer; /// Array mit 16 Speicherstellen von 1 bis 16 ///
  laenge: Integer;
  Zahl: Integer;
implementation

{$R *.dfm}

procedure TForm1.BerechnungsbuttonClick(Sender: TObject);
Var
     a ,b, i : Integer;
     c : extended;
     s : string;
     i1, i2 : Integer;
begin

    Ausgabeedit.Text:= '';

    
                               /// Hexadezimal in Dezimal ///
    IF ((Eingaberadiogroup.ItemIndex= 2) and (Ausgaberadiogroup.ItemIndex= 0)) then
      Begin
         i2 := StrToInt('$'+Eingabeedit.Text); // Umwandlung in INTEGER
         Ausgabeedit.Text := IntToStr(i2);
      end;


                              ///Dezimal in Hexadezimal///

    IF ((Eingaberadiogroup.ItemIndex=0) and (Ausgaberadiogroup.ItemIndex=2)) then
       begin
          i1 := StrToInt(Eingabeedit.Text); // wandelt String in Ganzzahl um
          Ausgabeedit.Text := Format('%x',[i1]); // Ausgabe als HEX
       end;


                               /// Dezimal in Binär///
    IF (( Eingaberadiogroup.ItemIndex=0) and (Ausgaberadiogroup.ItemIndex =1)) then
{ hier fehlt ein BEGIN -------------------------------------------------------------------------}        

    x:= StrtoInt (Eingabeedit.text); // Eingabe //

    ///***Beginn Umrechnung von Dezimal in Binär***///

          For i:= 1 to 16 do

              Begin
                BinArray[i]:= x mod 2;
                x := x div 2;
                Ausgabeedit.Text:= InttoStr(BinArray[i]) + Ausgabeedit.Text;
                  If x = 0 Then
                  break;
              End;

{und hier das zugehörige END ---------------------------------------------------------------------------}
                            ///Binär in Dezimal///
 
    IF ((Eingaberadiogroup.ItemIndex=1) and (Ausgaberadiogroup.Itemindex=0))then
{ hier fehlt ein BEGIN -------------------------------------------------------------------------}        

    s:= reverseString(Eingabeedit.Text); /// Drehen des Eingabestrings
    a:= Length(s); /// Ermittlung der Länge des Eingabestrings
    C:= 0; /// C wird auf 0 deklariert

              ///*** Beginn der Umrechnung von Binär in Dezimal ***///
      For b:= 1 to a do
        begin
          c := c+ Strtoint(s[b]) * power(2 , (-1 + b) ); (Ich habs in Internet gefunden aber versteh es kein bisschen!)
        end;
            Ausgabeedit.Text := FloattoStr(c); //*** Ausgabe aufs Ergebnisedit ***//
{und hier das zugehörige END ---------------------------------------------------------------------------}
Wieviele Deiner Fragen bleiben jetzt noch übrig?

Gruß
K-H
Programme gehorchen nicht Deinen Absichten sondern Deinen Anweisungen
R.E.D retired error detector
  Mit Zitat antworten Zitat