And if you don't trust the input, you can use the same technique more Safely like so:
#!/usr/bin/perl use warnings; use strict; use Safe; my @ops = qw( padany leaveeval lineseq bit_or left_shift const left_shift right_shift bit_and bit_xor bit_or negate i_negate not complement); my $safe = Safe->new(); $safe->permit_only(@ops); my $result = $safe->reval( '(1 << 18) | (0x00 << 12) | (0x00 << 6) | 0 +x00' ); printf "0x%x\n", $result;
In reply to Re: Convert bitwise value to its value
by sauoq
in thread Convert bitwise value to its value
by gibsonca
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |