---
Product: psd
Platform: python
Page Type: kb
Canonical URL: https://kb.aspose.org/psd/python/how-to-work-with-conversion-python
Last Updated: 2026-10-08
---

# How to Convert Raw Big-Endian Values in Python

Decode a 32-bit big-endian integer from raw PSD resource bytes using BigEndianBitConverter in Aspose.PSD FOSS for Python.

PSD files store most binary fields in big-endian byte order. When you need
to decode a raw field yourself — for example, from an image resource's raw
bytes — `BigEndianBitConverter` reads a big-endian 32-bit integer directly
from a byte array.

## Step-by-Step Guide

### Step 1: Install the Package

```bash
pip install aspose-psd-foss
```

---

### Step 2: Import Required Classes

```python
from aspose_psd_foss.psdimage import PsdImage
from aspose_psd_foss.bigendianbitconverter import BigEndianBitConverter
```

---

### Step 3: Read a Resource's Raw Bytes

`PsdImage.parsed_resources` returns the lower-level `UnknownResource`
objects, each exposing the raw payload via `data`:

```python
image = PsdImage.load("input.psd")

for resource in image.parsed_resources:
    raw = resource.data
```

---

### Step 4: Decode a 32-Bit Big-Endian Value

```python
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.

## Common Issues and Fixes

**`IndexError` when calling `to_int32`.** The byte array must have at
least 4 bytes available starting at `offset` — check `len(byte_array) >=
offset + 4` before calling.

**Values look byte-swapped.** Confirm you're not accidentally using a
little-endian conversion elsewhere in your own code — PSD resource and
header fields are consistently big-endian, which is exactly what
`BigEndianBitConverter` assumes.

## Frequently Asked Questions

### Does `BigEndianBitConverter` support other integer sizes?

In this FOSS build, `BigEndianBitConverter` provides `to_int32` only — for
16-bit or 64-bit big-endian values, decode the bytes manually with
Python's built-in `int.from_bytes(data, byteorder="big")`.

### Do I need this for normal document editing?

No — `BigEndianBitConverter` is a low-level utility for working with raw
bytes you've obtained yourself (for example, from an unrecognized image
resource). Typical loading, editing, and saving (see
[Working with the Core API](../how-to-work-with-psd-core-api-python/))
never requires it directly.

## See Also

- [Working with Resources](../how-to-work-with-resources-python/)
- [Working with the Core API](../how-to-work-with-psd-core-api-python/)
- [Aspose.PSD FOSS for Python — Frequently Asked Questions](../faq/)
- [Aspose.PSD — Enterprise Knowledge Base](https://kb.aspose.com/psd/)