File: endian.py

package info (click to toggle)
pygame 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 42,624 kB
  • sloc: ansic: 66,926; python: 48,742; javascript: 1,153; objc: 224; sh: 121; makefile: 59; cpp: 25
file content (20 lines) | stat: -rw-r--r-- 495 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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]