How to use a bitwise operator to pass multiple Integer values to a function for Pascal

1 Answer

0 votes
program MultiValueExample;

const
  ONE = $01;
  TWO = $02;
  THREE = $04;
  FOUR = $08;

procedure MultiValueExample(values: Integer);
begin
  if (values and ONE) = ONE then
    WriteLn('ONE');
    
  if (values and TWO) = TWO then
    WriteLn('TWO');
    
  if (values and THREE) = THREE then
    WriteLn('THREE');
    
  if (values and FOUR) = FOUR then
    WriteLn('FOUR');
end;

begin
  MultiValueExample(ONE or THREE or FOUR);
end.




(*
run:

ONE
THREE
FOUR
 
*)

 



answered Jan 15, 2025 by avibootz
...