Conversion

Conversion

PSD files store most binary fields in big-endian byte order. BigEndianBitConverter reads a big-endian 32-bit integer directly from a byte array, for cases where you’re working with raw bytes yourself — for example, from an unrecognized image resource.


Decoding a 32-Bit Big-Endian Value

from aspose_psd_foss.bigendianbitconverter import BigEndianBitConverter

data = bytes([0x00, 0x00, 0x04, 0x10])  # example 4-byte big-endian field
value = BigEndianBitConverter.to_int32(data, 0)
print(f"Decoded value: {value}")  # 1040

to_int32(byte_array, offset) reads 4 bytes starting at offset and combines them most-significant-byte-first.


Tips and Best Practices

  • BigEndianBitConverter provides to_int32 only in this FOSS build — for 16-bit or 64-bit big-endian values, decode manually with Python’s built-in int.from_bytes(data, byteorder="big").
  • This utility is for raw bytes you’ve already obtained (see Resources) — normal document loading, editing, and saving never requires it directly.

Common Issues

IssueCauseFix
IndexError calling to_int32The byte array has fewer than 4 bytes available starting at offsetCheck len(byte_array) >= offset + 4 before calling

FAQ

Do I need this for normal document editing?

No — it’s a low-level utility for raw bytes you’ve obtained yourself. Typical loading, editing, and saving (see Core API) never requires it directly.


API Reference Summary

Class/MethodDescription
BigEndianBitConverter.to_int32(byte_array, offset)Decodes a big-endian 32-bit integer

See Also