Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bit masks
#1
Hi, So I am writing this small program to determine door access allowed to users.
#create a special no. for storing an RFID card that determines which door I am #allowed to use
door1 = 1
door2 = 2
door3 = 4
door4 = 8
allowed = 0
#add a door or two: for example door 1 and door 3
allowed = allowed|door3
allowed = allowed|door1
print("Access to door 1 is: ", allowed&door1)
print("Access to door 2 is: ", allowed&door2)
print("Access to door 3 is: ", allowed&door3)
print("Access to door 4 is: ", allowed&door4)
The output is:
Access to door 1 is: 1
Access to door 2 is: 0
Access to door 3 is: 4
Access to door 4 is: 0

How can I change from outputting a number to outputting "allowed" and "not allowed" without creating a function to do so.
Reply


Messages In This Thread
Bit masks - by leodavinci1990 - Aug-10-2019, 05:59 PM
RE: Bit masks - by ThomasL - Aug-11-2019, 10:00 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020