[Tutor] Bit-level field extraction
S W Collier
stan at coll52.freeserve.co.uk
Tue May 16 21:13:03 CEST 2006
On Tuesday 16 May 2006 16:01, Alan Gauld wrote:
> Terry,
>
> Your approach is fine. Personally however I'd just have defined
> some constants and done a direct bitwise and - this is the
> approach used in the stat module:
>
> VMASK = 0x14 # 00011000
> VER00 = 0x00
> VER01 = 0x04
> VER10 = 0x10
> VER11 = 0x14
>
> version = byte & VMASK
> if version == VER00: #do something
> elif version == VER01: # do another
> Alan Gauld
Whoops, a typo I think. VMASK = 0x18 #00011000
or VMASK = 0x14 #00010100
Stan
More information about the Tutor
mailing list