![]() |
Re: Problem mit Integer zu Binär
Noch besser:
Delphi-Quellcode:
Oder gleich so: :zwinker:
Function IntToBinString( Const Value: Integer; Trim: Boolean = False ): String;
Var i: Byte; Begin SetLength( Result, 32 ); For i := 31 Downto 0 Do Begin If ( Value And ( 1 Shl i ) Shr i ) = 1 Then Result[ 32 - i ] := '1' Else Result[ 32 - i ] := '0'; End; If Trim Then Result := Copy( Result, Pos( '1', Result ), Length( Result ) ); End;
Delphi-Quellcode:
viel Spass damit :mrgreen:
Function IntToBinString( Const Value: Integer; Trim: Boolean = False ): String;
Var i: Byte; Begin SetLength( Result, 32 ); For i := 31 Downto 0 Do Begin Result[ 32 - i ] := Chr( ( Value And ( 1 Shl i ) Shr i ) + $30 ); End; If Trim Then Result := Copy( Result, Pos( '1', Result ), Length( Result ) ); End; bye |
Re: Problem mit Integer zu Binär
Wow, funzt gut.
Thanx ;) Falls Interesse besteht, würde ich mein Programm auch in der DP veröffentlichen... |
Re: Problem mit Integer zu Binär
Delphi-Quellcode:
Sorry, aber eure Sourcen sind manchmal echt vorn Ar... :) Soll keine Beleidigung sein sondern nur ein Hinweis darauf das man in PASCAL wirklich einfach und elegant programmieren kann.
function Bin(Value: Cardinal): String;
const Digit: array[Boolean] of Char = ('0', '1'); begin Result := ''; while Value <> 0 do begin Result := Digit[Odd(Value)] + Result; Value := Value shr 1; end; end; Gruß Hagen |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23: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