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 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 sys
print()
if sys.byteorder == "little":
    #intel, alpha
    print("Little-endian platform.")
else:
    #motorola, sparc
    print("Big-endian platform.")
print()

Sample Output:

Little-endian platform

Flowchart:

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

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

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 Python skills with w3resource's quiz



Python: Tips of the Day

Try-catch-else construct:

try:
  foo() 
except Exception: 
  print("Exception occured")
else:
  print("Exception didnt occur")
finally:
  print("Always gets here")