![]() |
Bin in Dec umwandeln
also ich will eine Binäre Zahl (Z.b. aus einer schnittstelle) in eine Dezimalzahl umwandeln.
Kennt ja jemand ne Lösung? also 1101011010010 in irgend ne NORMAL zahl verwandeln! |
Delphi-Quellcode:
(Normalerweise verwende ich i anstatt Index, aber das würde hier die Kursivschrift hervorrufen)
function BinToInt(const S: string): Integer;
var Index: Integer; begin Result := 0; for Index := Length(s) downto 1 do if s[Index] = '1' then Result := Result or (1 shl (Length(s) - Index); end; |
Hallo,
hier ist mal ein Lösungsansatz. Viel Spaß bye
Delphi-Quellcode:
function NumBin(B: string): Longint;
var Accum, Power: Longint; P: Byte; begin Power := 1; Accum := 0; for P := Length(B) downto 1 do begin If (B[P] = '0') or (B[P] = '1') then begin If B[P] = '1' then begin Inc(Accum, Power); end; Power := Power shl 1; end; end; NumBin := Accum; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:14 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