[Tutor] testing the bits of a binary number

Phil phillor9 at gmail.com
Wed Apr 27 01:47:12 EDT 2022


On 27/4/22 11:00, Cameron Simpson wrote:
>
> My own experience is that I'm usually concerned only with the
> combination of bits involved. Made up example:

Thank you Cameron for your reply and example code.


> What's your use case?

After experimenting with the new match-case statements I decided to 
refine a past project which turns on LEDS based on which bit is set. I 
came across a project yesterday that really had nothing to do with my 
project, or match-case statements, but it gave me an idea that made me 
think that there might be a more elegant way of solving the problem 
rather that shifting a bit mask to determine which bits are set. I've 
since refined the project in a minor way by eliminating a couple of 
lines of repeating code and coming up with a more meaningful name for a 
function.

-- 

Regards,
Phil



More information about the Tutor mailing list