Factor out bitfield manipulation