1. pygame
  2. pygame
  3. pygame

Commits

Lenard Lindstrom  committed c780a5d

Allow switching the byte order of a Python int to big or little endian

The pygame.tests.test_utils.endian module does machine independent
byte reorder of the first 4 bytes of a Python int.

  • Participants
  • Parent commits 927d431
  • Branches default

Comments (0)

Files changed (1)

File test/test_utils/endian.py

View file
  • Ignore whitespace
+# Module pygame.tests.test_utils.endian
+#
+# Machine independent conversion to little-endian and big-endian Python
+# integer values.
+
+import struct
+
+def little_endian_uint32(i):
+    """Return the 32 bit unsigned integer little-endian representation of i"""
+
+    s = struct.pack('<I', i)
+    return struct.unpack('=I', s)[0]
+
+def big_endian_uint32(i):
+    """Return the 32 bit unsigned integer big-endian representation of i"""
+
+    s = struct.pack('>I', i)
+    return struct.unpack('=I', s)[0]