Why bitwise operators, real-world use cases?

  • 0
    Studying the topic, bitwise operators.
    I would like to know the real application of bitwise operators.
    JavaScript Everett Santiago, Oct 31, 2020

  • 4 Answers
  • 0
    Packing bit "masks" into integer values ​​with different filters.

    Hash / Crypt Functional.

    Any simple overlay search with fuzzy matches (text, image, sound).
    Hannah Christensen

  • 0
    For example packing 32 values ​​into a whole.
    Atticus Woodward

  • 0
    Practically speaking, convert a string to a number:

    var a = '123';
    a = ~~a;
    console.log(typeof a); //number


    Discard signs after period:

    var b = 123.743932;
    console.log( ~~b ); // 123
    Ruby Jefferson

  • 0
    Well, for example, you can read how the file type is stored in Unix (regular file, directory / directory, several types of special files) and attributes / access rights. To find out if the file has the required type, you need to do "AND 0b1111_000_000_000_000" (this number is in binary form; underscores are for my convenience) and compare with the code of the required type.

    Here we see that bitwise operations allow working with parameters packed in several pieces into one integer.



    Or here's an example of using bitwise operations: " Integer base 2 logarithm in O (1) " ...
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!