Browse Source

rtl: added lo, hi for word, smallint, longword, longint

mattias 6 years ago
parent
commit
1a3c5c5a48
1 changed files with 48 additions and 0 deletions
  1. 48 0
      packages/rtl/system.pas

+ 48 - 0
packages/rtl/system.pas

@@ -289,6 +289,14 @@ procedure val(const S: String; out C : Cardinal; out Code: Integer); overload;
 procedure val(const S: String; out d : double; out Code : Integer); overload;
 procedure val(const S: String; out d : double; out Code : Integer); overload;
 procedure val(const S: String; out b : boolean; out Code: Integer); overload;
 procedure val(const S: String; out b : boolean; out Code: Integer); overload;
 function StringOfChar(c: Char; l: NativeInt): String;
 function StringOfChar(c: Char; l: NativeInt): String;
+function Lo(i: word): byte; overload;
+function Lo(i: smallint): byte; overload;
+function Lo(i: longint): byte; overload;
+function Lo(i: longword): byte; overload;
+function Hi(i: word): byte; overload;
+function Hi(i: smallint): byte; overload;
+function Hi(i: longword): byte; overload;
+function Hi(i: longint): byte; overload;
 
 
 {*****************************************************************************
 {*****************************************************************************
                           Other functions
                           Other functions
@@ -608,6 +616,46 @@ begin
   for i:=1 to l do Result:=Result+c;
   for i:=1 to l do Result:=Result+c;
 end;
 end;
 
 
+function Lo(i: word): byte;
+begin
+  Result:=i and $ff;
+end;
+
+function Lo(i: smallint): byte;
+begin
+  Result:=i and $ff;
+end;
+
+function Lo(i: longint): byte;
+begin
+  Result:=i and $ffff;
+end;
+
+function Lo(i: longword): byte;
+begin
+  Result:=i and $ffff;
+end;
+
+function Hi(i: word): byte;
+begin
+  Result:=(i shr 8) and $ff;
+end;
+
+function Hi(i: smallint): byte;
+begin
+  Result:=(i shr 8) and $ff;
+end;
+
+function Hi(i: longword): byte;
+begin
+  Result:=(i shr 16) and $ffff;
+end;
+
+function Hi(i: longint): byte;
+begin
+  Result:=(i shr 16) and $ffff;
+end;
+
 function Assigned(const V: JSValue): boolean; assembler;
 function Assigned(const V: JSValue): boolean; assembler;
 asm
 asm
   return (V!=undefined) && (V!=null) && (!rtl.isArray(V) || (V.length > 0));
   return (V!=undefined) && (V!=null) && (!rtl.isArray(V) || (V.length > 0));