From 48d07304a6ba3c35d3f19faea3d54a7a869dfc22 Mon Sep 17 00:00:00 2001
From: Martin Nilsson <mani@lysator.liu.se>
Date: Mon, 15 Mar 2004 22:51:25 +0100
Subject: [PATCH] Hopefully I never have to write this code again....
 (swap_word, swap_long)

Rev: lib/modules/Int.pmod:1.7
---
 lib/modules/Int.pmod | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lib/modules/Int.pmod b/lib/modules/Int.pmod
index 51526548ed..77228ac136 100644
--- a/lib/modules/Int.pmod
+++ b/lib/modules/Int.pmod
@@ -41,3 +41,15 @@ constant NATIVE_MAX = __builtin.NATIVE_INT_MAX;
 //! @expr{--without-bignum@} (which is discouraged), then all
 //! arithmetic operations will instead silently wrap around at these
 //! limits.
+
+//! Swaps the upper and lower byte in a word.
+int(0..65535) swap_word(int(0..65535) i) {
+  return ((i&255)<<8) | ((i&(255<<8))>>8);
+}
+
+//! Swaps the upper and lower word in a longword, and the upper and
+//! lower bytes in the words. Simply put, the bytes are reversed.
+int(0..4294967295) swap_long(int(0..4294967295) i) {
+  return ((i&255)<<24) | ((i&(255<<8))<<8) |
+    ((i&(255<<16))>>8) | ((i&(255<<24))>>24);
+}
-- 
GitLab