w3resource

Python: Test whether the system is a big-endian platform or little-endian platform

Python Basic: Exercise-77 with Solution

Write a Python program to test whether the system is a big-endian platform or a little-endian platform.

sys.byteorder: An indicator of the native byte order. This will have the value 'big' on big-endian (most-significant byte first) platforms, and 'little' on little-endian (least-significant byte first) platforms.

Sample Solution:

Python Code:

# Import the sys module to access system-specific information.
import sys

# Display a blank line for clarity.
print()

# Check if the byte order of the platform is "little" (e.g., Intel, Alpha) and display a corresponding message.
if sys.byteorder == "little":
    print("Little-endian platform.")
else:
    # If the byte order is not "little," assume it's "big" (e.g., Motorola, SPARC) and display a corresponding message.
    print("Big-endian platform.")

# Display another blank line for clarity.
print()

Sample Output:

Little-endian platform

Flowchart:

Flowchart: Test whether the system is a big-endian platform or little-endian platform.

Python Code Editor:

 

Previous: Write a Python program to get the command-line arguments (name of the script, the number of arguments, arguments) passed to a script.
Next: Write a Python program to find the available built-in modules.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/python-basic-exercise-77.php