By using for loop and ord() function
The ord() function is used to return the number representing the Unicode code of a specified byte character.
Syntax:
ord(character)
Parameters: This function accepts a single parameter which is illustrated below:
- character: This is the specified byte string.
Return values: This function returns the number representing the Unicode code of a specified byte character.
Example: Python program to a byte string to a list of integers
Python3
# Python program to illustrate the # conversion of a byte string # to a list of integers # Initializing a byte string S = "GFG is a CS Portal" nums = [] # Calling the for loop to iterate each # characters of the given byte string for chr in S: # Calling the ord() function # to convert the specified byte # characters to numbers of the unicode nums.append( ord ( chr )) # Printing the unicode of the byte string print (nums) |
Output:
[71, 70, 71, 32, 105, 115, 32, 97, 32, 67, 83, 32, 80, 111, 114, 116, 97, 108]
Time Complexity: O(n)
Auxiliary Space: O(n)
Python program to convert a byte string to a list of integers
Given a byte string. The task is to write a Python program to convert this byte of string to a list of integers.
Contact Us