Part of the series

Several example codes

~1 min read • Updated Sep 24, 2025

Program Overview

This Python program receives a list of integers and converts it into a byte array using the bytearray() constructor.
Byte arrays are useful for binary data storage, low-level processing, and efficient memory usage.


Python Code:


# Sample list of integers (values must be between 0 and 255)
numbers = [65, 66, 67, 68]

# Convert the list to a byte array
byte_arr = bytearray(numbers)

# Display the result
print("Byte array:", byte_arr)

Sample Output:


Byte array: bytearray(b'ABCD')

Explanation:

- The list numbers contains integer values within the valid byte range (0–255)
- The bytearray() function converts the list into a byte array
- If the values correspond to ASCII codes, the output will be readable as characters
- The result is printed using print()


Written & researched by Dr. Shahin Siami