# bitfield format: xxxMMMxx my @msgs = ( 'a' .. 'i' ); my $msg = $msgs[ ( $bitfield >> 2 ) && 7 ];
It's also used in doing checksums, hashing, encryption, doing exponent changes in fixed-point arithmetic, quick multiplications and divisions by powers of two, etc, etc.
Update: I missed that you also asked about bitwise operators. They are usually used to extract informations from numbers that contains multiple flags or fields. For example, system returns a number that consists of 3 fields:
bit15 bit0 | | v v C SSSSSSS EEEEEEEE C = Core dumped? S = Signal that caused program to exit E = Process's exit code.
These can be extracted as follows:
$core_dumped = ($? >> 15) & 1; $signal = ($? >> 8) & 127; $exit_code = $? & 255
In reply to Re: Shift Operators And Bitwise Operators
by ikegami
in thread Shift Operators And Bitwise Operators
by biohisham
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |