how to get bit info

Laurent Verweijen somelauw at gmail.com
Thu Jun 17 16:08:47 EDT 2010


Op donderdag 17-06-2010 om 12:51 uur [tijdzone -0700], schreef Back9: 
> Hi,
> 
> I have one byte data and want to know each bit info,
> I mean how I can know each bit is set or not?
> 
> TIA

def bitset(x, n):
"""Return whether nth bit of x was set"""
return bool(x & (1 << n))




More information about the Python-list mailing list