breaking a 32-bit number into individual fields
python
Solution
Standard library module struct does short work of it:
>>> import struct
>>> x = 0xa1a2a3a4
>>> struct.unpack('4B', struct.pack('>I', x))
(161, 162, 163, 164)
"packing" with format `'>I'` makes `x` into a 4-byte string in big-endian order, which can then immediately be "unpacked" into four unsigned byte-size values with format `'4B'`. Easy peasy.
Problem
Is there a quick way in python to split a 32-bit variable, say, `a1a2a3a4` into `a1`, `a2`, `a3`, `a4` quickly? I've done it by changing the value into hex and then splitting it, but it seems like a waste of time doing `int`->`string`->`int`.