Does Delphi and FPC have MakeWord functions (out of two bytes or chars)?

Viewed 583

These functions are useful:

function MakeWord(low, high: char): word;
begin
  result := byte(high) shl 8 + byte(low);
end; 

function MakeWord(low, high: byte): word;
begin
  result := high shl 8 + low;
end; 

However I am wondering if these kinds of functions (could be implemented differently) already exist somewhere (not in a windows api specific file, but rather a cross platform RTL function).

Example use case: take the two characters GT and make a WORD result out of it.

MakeWord('G','T');

I find this more readable than inserting SHL/SHR AND/OR hex operations and other hacks in the code that do not describe what the code is doing... so surely these functions exist somewhere already? Or do people roll their own in their applications?

Or something like:

var x: word;
begin
  lo(x) := byte('G');
  hi(x) := byte('T');
end;

However, that will not work as the left side cannot be assigned to: but it is more readable, than some other solutions, IMO.

I think I have seen LoWord and HiWord functions too (or LoByte, HiByte) but usually in read only cases. What about writing to the hi and lo?

2 Answers
Related