Managing User Permissions with Bitwise Operators

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ส.ค. 2020
  • There are frequently different types of users on a website who have different levels of access and different task permissions. This tutorial explains how you can use a single integer to represent any combination of access permissions, all thanks to the bitwise operators. The bitwise operators will let us manipulate and interrogate numbers at the binary level.
    Code from video: gist.github.com/prof3ssorSt3v...
    Bitwise operator basics video: • Managing User Permissi...

ความคิดเห็น • 15

  • @jeanmarcpourchel307
    @jeanmarcpourchel307 4 ปีที่แล้ว +6

    Another great tip!
    Bitwise operators are underrated and forgotten most of the time.
    Thanks for reminding us that they exist.
    ...and as always thanks for teaching

  • @aquib-J
    @aquib-J 4 ปีที่แล้ว +1

    I always imagined something similar if I had to write a permission system. Very neat idea. Unix continues to inspire with its clever Ideas 😃. Thanks

  • @noeascencio9444
    @noeascencio9444 2 ปีที่แล้ว

    This is the best way to save permissions, if you slit it into categories, each category can have at least 32 permissions. I'm starting to use it cause i have 11 categories and each one has about 10 permissions. This is exactly what I needed to get me started. I'm using arrays for each category :)

  • @write2sampath1
    @write2sampath1 4 ปีที่แล้ว

    Wow !! Never knew the power of bitwise operators. This is 🔥. Would love to see more content like this.

  • @HappyLifege
    @HappyLifege 4 ปีที่แล้ว

    Insightful. Thank you for this lesson!

  • @mykalimba
    @mykalimba 4 ปีที่แล้ว +4

    Back when the cost of memory was exorbitant, any coder worth his/her salt (myself included) was encoding data like this.

  • @chesterxp508
    @chesterxp508 2 ปีที่แล้ว

    Another very cool tutorial!

  • @smajdovamanka
    @smajdovamanka ปีที่แล้ว

    THANK YOU SO MUCH FOR THiS!

  • @vwesih8231
    @vwesih8231 3 ปีที่แล้ว +3

    this.access &= ~perm can also be removed

  • @pnutbtrr7717
    @pnutbtrr7717 2 ปีที่แล้ว

    Steve and Joanne out here dying of thirst

  • @grijjly6091
    @grijjly6091 ปีที่แล้ว

    for remove function, this.access &= ~perm does the job without checking it

  • @adicide9070
    @adicide9070 3 ปีที่แล้ว

    Hi Steve, was trying this out along with the vid and I figured maybe we could check for presence of a permission before removing with XOR this way:
    if (this.access & permission) {
    this.access ^ permission
    }
    Not sure but seems to make sense. Quick question to go along with this, though: How come you choose to not go with labels for the console log of available permissions? Is there any advantage to having nums there which we'd have to look up to know what they reference?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว

      yes. but don't forget the assignment. this.access = this.access ^ permission
      I use the getAll method to help people understand the step a bit easier.

    • @adicide9070
      @adicide9070 3 ปีที่แล้ว +1

      @@SteveGriffith-Prof3ssorSt3v3 right, thanks!