in reply to Hex/binary/Decimal

Bit shifting and bitwise and:
my $hex = hex("1c023d64"); my $mask = 31 << 5; my $result = ($hex & $mask) >> 5; printf "Hex: %30b\n", $hex; printf "Mask: %30b\n", $mask; printf "Result: %30b (%d)\n", $result, $result;
shows the result like this:
Hex: 11100000000100011110101100100 Mask: 1111100000 Result: 1011 (11)

Replies are listed 'Best First'.
Re^2: Hex/binary/Decimal
by thekestrel (Friar) on Feb 11, 2005 at 23:21 UTC

    Saintmike,
    Thankyou =, exactly what I need, I haven't done bit twiddling in perl before. So simple.....

    Warm Regards Paul.