[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
IntToBin
Author : DJ_Sannie
E-Mail : DJ_Sannie@yahoo.com
Date : March 30, 2004






function IntToBin( Int: Integer ): String;
var
  i, j: Integer;
begin
  Result := '';
  i := 0;
  j := 1;
  while i = 0 do
    if( ( Int Mod (j*2) ) = Int )
      then i := j
      else j := j * 2;
  while i > 0 do
  begin
    if( ( Int div i ) > 0 ) then
    begin
      Int := Int - i;
      Result := Result + '1';
    end
    else Result := Result + '0';
    i := Trunc( i * 0.5 );
  end;
end;
function Int64ToBin(Num: Int64; Length: integer): string;
var
  i: Int64;
begin
  i := 1;
  Result := '';
  while (i <= Num) or (system.Length(Result) < Length) do begin
    if Num and i = i then
      Result := '1' + Result
    else
      Result := '0' + Result;
    i := i * 2;
  end;
end;
function FastIntToBin(Num: cardinal; Length: integer): string;
var
  i: cardinal;
begin
  i := 1;
  Result := '';
  while (i <= Num) or (system.Length(Result) < Length) do begin
    if Num and i = i then
      Result := '1' + Result
    else
      Result := '0' + Result;
    i := i * 2;
  end;
end;


last edited (April 4, 2004) by zibadian, Number of views: 3006, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.