Registriert seit: 10. Sep 2004
Ort: Mönchengladbach
833 Beiträge
Delphi 7 Enterprise
|
Re: Problem mit Integer zu Binär
21. Jan 2005, 14:45
Noch besser:
Delphi-Quellcode:
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;
Oder gleich so:
Delphi-Quellcode:
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;
viel Spass damit
bye
Christian
|
|
Zitat
|