Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Borland Delphi > Skybuck present...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 3735 of 3851
Post > Topic >>

Skybuck presents ****ftLeft( Left, Right, ****ft ) and ****ftRight( Right, Left, ****ft )

by "Skybuck Flying" <BloodyShame@[EMAIL PROTECTED] > May 5, 2008 at 06:47 PM

Hello,

I think these two functions will come in very handy to solving the "write 
longword bits" problem.

****ftLeft( Left, Right, ****ft )
****ftRight( Right, Left, ****ft )

****fting with extra inputs is what is required to solve it nicely.

// Begin of Code ***

program Project1;

{$APPTYPE CONSOLE}

{

Skybuck presents ****ftLeft( Left, Right, ****ft ) and ****ftRight( Right, 
Left, ****ft )

version 0.01 created on 5 may 2008 by Skybuck Flying.

Be carefull though, the ****ft parameter must be 0 to 31.

}

uses
 SysUtils;

// make overloaded versions for easy coding
// display in big endian.
procedure WriteBitPattern( const ParaByte : byte ); overload;
type
 TbitRange = 0..7;
 TbitSet = set of TbitRange;
var
 vBit : TbitRange;
begin
 for vBit:= 0 to 7 do
 begin
  if vBit in TbitSet(ParaByte) then
  begin
   write('1');
  end else
  begin
   write('0');
  end;
 end;
end;

procedure WriteBitPattern( const ParaWord : word ); overload;
type
 TbitRange = 0..15;
 TbitSet = set of TbitRange;
var
 vBit : TbitRange;
begin
 for vBit:= 0 to 15 do
 begin
  if vBit in TbitSet(ParaWord) then
  begin
   write('1');
  end else
  begin
   write('0');
  end;
 end;
end;

procedure WriteBitPattern( const ParaLongWord : longword ); overload;
type
 TbitRange = 0..31;
 TbitSet = set of TbitRange;
var
 vBit : TbitRange;
begin
 for vBit:= 0 to 31 do
 begin
  if vBit in TbitSet(ParaLongWord) then
  begin
   write('1');
  end else
  begin
   write('0');
  end;
 end;
end;

function ****ftLeft( Left : longword; Right : Longword; ****ft : longword )
: 
longword;
asm
 shld eax, edx, cl
end;

function ****ftRight( Right : longword; Left : longword; ****ft : longword )
: 
longword;
asm
 shrd eax, edx, cl
end;

procedure Main;
var
 vLeft : longword;
 vRight : longword;
 v****ft : longword;
 vResult : longword;
begin
 writeln('program started');

 for v****ft := 0 to 31 do
 begin
  vLeft := 0;
  vRight := 1 + 0 + 8 + 0 + 32 + 2147483648;
  vResult := ****ftLeft( vLeft, vRight, v****ft );
  Writeln( '****ftLeft vLeft: ', vLeft, ' vRight: ', vRight, ' vResult: ', 
vResult );
  WriteBitPattern( vLeft ); write( ' ' );
  WriteBitPattern( vRight ); write( ' ' );
  WriteBitPattern( vResult ); writeln;
  Writeln;
 end;

 for v****ft := 0 to 31 do
 begin
  vLeft := 1 + 0 + 8 + 0 + 32 + 2147483648;
  vRight := 0;
  vResult := ****ftRight( vRight, vLeft, v****ft );
  Writeln( '****ftRight vRight: ', vRight, ' vLeft: ', vLeft, ' vResult: ',

vResult );
  WriteBitPattern( vRight ); write( ' ' );
  WriteBitPattern( vLeft ); write( ' ' );
  WriteBitPattern( vResult ); writeln;
  Writeln;
 end;

 writeln('program finished');
end;

begin
 try
  Main;
 except
  on E:Exception do
   Writeln(E.Classname, ': ', E.Message);
 end;
 readln;
end.

// *** End of Code ***

Bye,
  Skybuck.
 




 1 Posts in Topic:
Skybuck presents ShiftLeft( Left, Right, Shift ) and ShiftRight(
"Skybuck Flying"  2008-05-05 18:47:46 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 13:37:25 CDT 2008.