Color representation as rgb, int and hex

MRAB python at mrabarnett.plus.com
Sun Sep 8 16:18:18 EDT 2019


On 2019-09-08 20:58, Eko palypse wrote:
> I'm confused about the following
> 
> import sys
> print(tuple(bytes.fromhex('282C34')))
> print(tuple((0x282C34).to_bytes(3, byteorder=sys.byteorder)))
> 
> which results in
> 
> (40, 44, 52)
> (52, 44, 40)
> 
> on my machine. Shouldn't I expect the same result?
> 
You haven't said whether your machine is big-endian or little-endian.

On a little-endian machine a 4-byte integer 0x282C34 is stored as:

     34 2C 28 00
     -> increasing address ->

On a big-endian machine a 4-byte integer 0x282C34 is stored as:

     00 28 2C 34
     -> increasing address ->



More information about the Python-list mailing list