Re: Extracting bits out of huge numbers




Quoth bugbear <bugbear@xxxxxxxxxxxxxxxxxxxxxxxxx>:
hofer wrote:
>>
>>Example Bits 16 bis 12 should result in 0b00001 == 0x1 == 1
>> Bits 17 bis 12 should result in 0b100001 == 0x21 == 33


what do you mean by
"Bits 16 bis 12"

and

"Bit 17s bis 12"

what is "bis" ?

'To' in English, 'through' or 'thru' in American. So, the OP wishes to
look at only the bits from bit 16 to bit 12; something like

my $num = ...;

my $mask = 0;
$mask |= 1<<$_ for 12..16;
$num &= $mask;
$num >>= 12;

would do what he wants, but slowly, and with small(ish) integers only.

Ben

--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* ben@xxxxxxxxxxxx *
.