chami.com/tips/
Last  Home  Next
 Internet
 Programming
 Windows


Click for details
Keywords
Delphi 1.x
Delphi 2.x
Delphi 3.x
Delphi
Functions
Source Code

Downloads
mkword.pas

Make or break your WORDs

    See Also
  Using Format() to format your code

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. Right click mkword.pas to download.
 
Related Links Email Print 
Created on 7-Nov-1996. Source code colorized using CodeColorizer.
Copyright (C) 1996-99 Chami.com All Rights Reserved. Reproduction in whole or in part
or in any form or medium without express written permission of Chami.com is prohibited.
Information on this page is provided as-is without warranty of any kind. Use at your own risk.
Free Downloads | Products & Services | Privacy Statement | Terms & Conditions | Advertising Info