What is the functionality of the Bitwise and Bitshift operators in Java? -


i understand bitwise , bitshift operators in java do, dont understand practical use is. instance, when useful use " ~, <<, >>, >>>, &, ^,| " modify or compare bits of values?

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

always 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

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -