hex to bin 16 bit word

Grant Edwards invalid at invalid.invalid
Fri Apr 27 15:11:47 EDT 2012


On 2012年04月27日, Paul Rubin <no.email at nospam.invalid> wrote:
> python <w.g.sneddon at gmail.com> writes:
>> What to decode hex '0xC0A8' and return signed short int.
>> Is this right?
>> n = int('0xC0A8', 16)
> if n >= 0xffff:
> n -= 0x10000

Yes, as long as the input value doesn't exceed 0x1ffff. This is
probably better:
 n = int('0xc0a8'16) & 0xffff
-- 
Grant Edwards grant.b.edwards Yow! What PROGRAM are they
 at watching?
 gmail.com 


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /