summaryrefslogtreecommitdiff
path: root/lowlevelunit.pas
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2015-10-19 19:42:43 +0200
committerErich Eckner <git@eckner.net>2015-10-19 19:42:43 +0200
commit19a3c272ece8d4187119b850d13f4de88f427d62 (patch)
tree3e5ba81bdf0613964700b76d4361983ece510afa /lowlevelunit.pas
parentf840c8fa63134a71419caf9058561341c4f6970e (diff)
downloadunits-19a3c272ece8d4187119b850d13f4de88f427d62.tar.xz
mirrorBits neu in lowlevelunit.pas
Diffstat (limited to 'lowlevelunit.pas')
-rw-r--r--lowlevelunit.pas38
1 files changed, 38 insertions, 0 deletions
diff --git a/lowlevelunit.pas b/lowlevelunit.pas
index cf6f883..7ad86a4 100644
--- a/lowlevelunit.pas
+++ b/lowlevelunit.pas
@@ -82,6 +82,10 @@ function hexDump(p: pointer; cnt: longint): string;
function base64ToBin(var s: string): boolean;
function base64Decode(const s: string; out i: qword): boolean; overload;
function base64Decode(const s: string; out i: longword): boolean; overload;
+function mirrorBits(qw: qword): qword; overload;
+function mirrorBits(lw: longword): longword; overload;
+function mirrorBits(w: word): word; overload;
+function mirrorBits(b: byte): byte; overload;
var
base64Chars: array[0..63] of char;
@@ -709,6 +713,40 @@ begin
i:=0;
end;
+function mirrorBits(qw: qword): qword;
+begin
+ result:=
+ (mirrorBits(longword(qw and $ffffffff)) shl 32) or
+ mirrorBits(longword(qw shr 32));
+end;
+
+function mirrorBits(lw: longword): longword;
+begin
+ result:=
+ (mirrorBits(word(lw and $ffff)) shl 16) or
+ mirrorBits(word(lw shr 16));
+end;
+
+function mirrorBits(w: word): word;
+begin
+ result:=
+ (mirrorBits(byte(w and $ff)) shl 8) or
+ mirrorBits(byte(w shr 8));
+end;
+
+function mirrorBits(b: byte): byte;
+begin
+ result:=
+ byte(odd(b shr 7)) or
+ (byte(odd(b shr 6)) shl 1) or
+ (byte(odd(b shr 5)) shl 2) or
+ (byte(odd(b shr 4)) shl 3) or
+ (byte(odd(b shr 3)) shl 4) or
+ (byte(odd(b shr 2)) shl 5) or
+ (byte(odd(b shr 1)) shl 6) or
+ (byte(odd(b)) shl 7);
+end;
+
var b: byte;
begin