language agnostic - Real world use cases of bitwise operators -


what real world use cases of following bitwise operators?

  • and
  • xor
  • not
  • or

  • bit fields (flags)
    they're efficient way of representing state defined several "yes or no" properties. acls example; if have let's 4 discrete permissions (read, write, execute, change policy), it's better store in 1 byte rather waste 4. these can mapped enumeration types in many languages added convenience.

  • communication on ports/sockets
    involves checksums, parity, stop bits, flow control algorithms, , on, depend on logic values of individual bytes opposed numeric values, since medium may capable of transmitting 1 bit @ time.

  • compression, encryption
    both of these heavily dependent on bitwise algorithms. @ deflate algorithm example - in bits, not bytes.

  • finite state machines
    i'm speaking of kind embedded in piece of hardware, although can found in software too. these combinatorial in nature - might literally getting "compiled" down bunch of logic gates, have expressed and, or, not, etc.

  • graphics there's hardly enough space here every area these operators used in graphics programming. xor (or ^) particularly interesting here because applying same input second time undo first. older guis used rely on selection highlighting , other overlays, in order eliminate need costly redraws. they're still useful in slow graphics protocols (i.e. remote desktop).

those first few examples came - hardly exhaustive list.


Comments

Popular posts from this blog

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -

openssl - Load PKCS#8 binary key into Ruby -