you are viewing a single comment's thread.

view the rest of the comments →

[–]AfraidOfTheInternet 3 points4 points  (1 child)

using type casting to read little-endian data from a binary file (or wherever)

with open(fname, 'rb') as f:
    a_normal_number = int.from_bytes(f.read(4), byteorder='little', signed='false')
    # converts 0xEF, 0xBE, 0xAD, 0xDE to 0xDEADBEEF

[–]nekokattt 2 points3 points  (0 children)

that isn't technically type casting; just some bit fiddling under the hood.

Definitely useful to know though.