I have one byte data and want to know each bit info,
I mean how I can know each bit is set or not?
... print "Bit 1 is set!"
... else:
... print "Bit 1 is not set!"
Bit 1 is set!... byte = byte | BIT_6
... print "Bit 6 wasn't set, BUT NOW IS."
Bit 6 wasn't set, BUT NOW IS.99
(I added 'how to set a specific bit' just cuz)
Basically, those BIT_X lines are creating numbers which have *only* the
specified bit set. Then you do "byte & BIT_X", and that will return 0 if
the byte doesn't have the specified bit in it. You can then set the bit
with "byte | BIT_X", and unset the bit with "byte ^ BIT_X".
--
Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog:
http://meh.ixokai.io/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)
iQEcBAEBAgAGBQJMGoINAAoJEKcbwptVWx/lMNAH/3B30j2W6s5K9D++2otmaob5
EP2L8AX59qRX40nClxkZdrxI9na8/N6K0GNz/kAWQHL4M5jUe+2DHa4ZxCT6U+Rd
Y/u5kB2rhWwsMD5rlLVirPiZDAcqH2JGbtAftU57ycl2RBM1gMySkyAkIlQZWIeo
Vsuh0KRsggRNZxQq+ocoxTcFt1sfG9tCUkRjkx2CyhZGVMi3OXMjlbecOPsC3AVy
T5BE8qPg3Wxw3Hg6/M9x1cGkbeccDgP3A2kapTp7lGEACx+EbniD77Iz1LFgtmoC
n2UCfF3dOR00Wskexa5BSN9HvPJnNCCn1OShLg9xlr1/YW7rdn+UBHISdF4TmIo=
=6tdY
-----END PGP SIGNATURE-----