In Python?

Do you mean a binary number with 24 bits or an integer with 24 digits?

A binary number with 24 bits, sorry

Why simple! Convert your values to decimal and then back to binary after doing the masking!

If you're using Python 2.6 or 3.0 you can make use of the bin() and int() conversions to make this super easy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.