Make or break your WORDs
Did you ever needed to create a single 16-bit number out of two 8-bit bytes? Try this:
{$apptype console}
program makewrd;
uses
Windows, SysUtils;
var
b1, b2 : byte;
w : word;
begin
b1 := 128;
b2 := 255;
{ create a WORD (16-bit integer)
by concatenating two BYTEs (8-bit) }
w := MAKEWORD( b1, b2 );
WriteLn( Format( '%d', [ w ] ) );
{ now break up the WORD we created
in to it's original two bytes }
WriteLn( Format( 'b1 = %d, b2 = %d',
[ LOBYTE( w ), HIBYTE( w ) ] ) );
end.
Listing #1 : Delphi code. Download
mkword (0.42 KB).
Applicable Keywords : Delphi, Delphi 1.x, Delphi 2.x, Delphi 3.x, Functions, Source Code