Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Binäre subtraktion? (https://www.delphipraxis.net/65714-binaere-subtraktion.html)

Phantom1 20. Mär 2006 14:29


Binäre subtraktion?
 
Ich suche momentan eine einfache function um 2 Binärzahlen zu subtrahieren.

Fürs addieren habe ich folgenen Code:
Delphi-Quellcode:
function Addieren(Val1, Val2: TBitInt): TBigInt;
var i: integer; merke: Boolean;
begin
  merke:=False;
  for i:=Low(Val1) to high(Val1) do begin
    Result[i]:=(Val1[i] xor Val2[i]) xor merke);
    merke:=Val1[i] and Val2[i] or ((Val1[i] or Val2[i]) and merke);
  end;
end;
Ich komme grad nich drauf, wie ich es bei der Subtraktionen machen muss:
Delphi-Quellcode:
function Subtrahieren(Val1, Val2: TBitInt): TBigInt;
var i: integer; merke: Boolean;
begin
  merke:=False;
  for i:=Low(Val1) to high(Val1) do begin
    Result[i]:= ...
    merke:= ...
  end;
end;

brechi 20. Mär 2006 14:33

Re: Binäre subtraktion?
 
schau dir mal das Einer/Zweierkomplement an. (Wiki)
Dann kannst du die Addition dafür benutzen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:20 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz