Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- int24 = array[0..2] of byte; //operations are slower, but memory is 3 bytes
- function IntToInt24(x: integer): int24;
- begin
- result[0] := x and 255;
- result[1] := (x shr 8) and 255;
- result[2] := (x shr 16) and 255;
- end;
- function Int24ToInt(x: int24): integer;
- begin
- result := (x[2] shl 16) + (x[1] shl 8) + x[0];
- end;
- procedure read24(var x: int24);
- var
- y: integer;
- begin
- read(y);
- x := IntToInt24(y);
- end;
- procedure readln24(var x: int24);
- var
- y: integer;
- begin
- readln(y);
- x := IntToInt24(y);
- end;
- procedure write24(x: int24);
- begin
- write(Int24ToInt(x));
- end;
- procedure writeln24(x: int24);
- begin
- writeln(Int24ToInt(x));
- end;
- function sloj24(x, y: int24): int24;
- begin
- result[0] := (x[0] + y[0]) and 255;
- result[1] := (x[1] + y[1] + (x[0] + y[0]) shr 8) and 255;
- result[2] := (x[2] + y[2] + (x[1] + y[1] + (x[0] + y[0]) shr 8) shr 8) and 255;
- end;
- function umn24(x, y: int24): int24;
- begin
- result := IntToInt24(Int24ToInt(x) * Int24ToInt(y));
- end;
- function div24(x, y: int24): int24;
- begin
- result := IntToInt24(Int24ToInt(x) div Int24ToInt(y));
- end;
- function mod24(x, y: int24): int24;
- begin
- result := IntToInt24(Int24ToInt(x) mod Int24ToInt(y));
- end;
Advertisement
Add Comment
Please, Sign In to add comment