Coding Shorts: Demystifying Bitwise Operators in C#

Поделиться
HTML-код
  • Опубликовано: 13 сен 2024

Комментарии • 22

  • @tommo120
    @tommo120 2 года назад +4

    Brakes are a feature? I thought they were essential 😂
    Thanks for the video! Still struggling to completely wrap my head around this, but I feel I understand it more than I did before I watched this :)

  • @marklord7614
    @marklord7614 2 года назад +3

    Very nice video. When not dealing with these topics for a while, there's nothing like a good refresher to get you back on track. Thanks.

  • @kinglygaurav
    @kinglygaurav 5 месяцев назад

    Thank you so much Shawn!
    That Write utility helped me to understand the leetcode bit manipulation questions.
    And that Flags part is awesome!
    Or to collect, And to check.
    Again, it all goes back to the Write utility function.
    Ty again and keep up the good work!

  • @sampannapokhrel
    @sampannapokhrel 9 месяцев назад +1

    FYI: 0b0100 is 4 not 8. The video is great

  • @imaginative-monkey
    @imaginative-monkey 3 года назад +5

    A very nice video. I would personally set the [Flags] enum values in binary, which makes it very visual that each enum value has only one bit set to '1'.

  • @ChrisG0
    @ChrisG0 3 года назад +1

    Yes very helpful. XOR ^ was something that I never really learned. Adding in binary very cool. The binary | were you add multiple enums or options to one config type variable is useful. I think the only time I've used it was for global decimal styles number formatting, etc.

    • @swildermuth
      @swildermuth  3 года назад

      It took me a long time to get my head around it. I just bluffed early in my career (switched it back and forth until it worked). Glad it helped.

    • @imaginative-monkey
      @imaginative-monkey 3 года назад

      To me, one of the coolest applications of XOR is to 'toggle' a bit. In the example of this video, you can write "features ^= Features.Radio" to toggle it's value, because if the radio bit in 'features' is already set with '1', then 1 ^ 1 = 0 and if it is '0', then 0 ^ 1 = 1.

    • @aroundme3184
      @aroundme3184 2 года назад

      Cool fact: Bitwise for Enum, consume less memory compare to list to hold multiple enum values

  • @ChrisUG
    @ChrisUG Год назад

    I don't get why the [Flags] attribute can't tell the compiler to properly binary space the values of the enum. If it doesnt work when you don't do it precicely, why not just automate it.

  • @kubastanek14
    @kubastanek14 3 года назад +2

    Wouldn't feature.HasFlag(Brakes) be better for such a situation? It's more readable and it's type-safe.

    • @swildermuth
      @swildermuth  3 года назад +3

      In fact, yes. They've wrapped this to allow for you to ignore the bitwise math. I didn't know about this. Thanks for sharing.

    • @chadmwest
      @chadmwest 2 года назад

      This is all really damn cool. I'm glad I watched the video and learned about the binary operations on enums _and_ the HasFlag method.

  • @tariq9100
    @tariq9100 2 года назад

    nice explanation , thanks

  • @MrZnSstr
    @MrZnSstr 2 года назад

    I did some leetcode exercises and there is always one brilliant guy using them and it frustrates me because I dont know when to use them, like problem doesnt tell me ok this can be done bitwise operators because the examples I watched are simplistic and trivial

  • @alakhkaushik
    @alakhkaushik 2 года назад

    How to use csi with VS Code... I see message - 'csi' is not recognized as an internal or external command

    • @swildermuth
      @swildermuth  2 года назад

      What do you mean "csi"?

    • @alakhkaushik
      @alakhkaushik 2 года назад

      @@swildermuth I meant to refer c# interactive... I have been able to figure it out and I could do it just by setup of EnvironmentPath... Thank you for quick reply.. apparently I missed this notification.

    • @sampannapokhrel
      @sampannapokhrel 9 месяцев назад

      @@alakhkaushik Can you please explain how you did that? Would love to know it without using any extensions