Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Bitwise Operator Error

by broomduster (Priest)
on Oct 02, 2008 at 18:49 UTC ( [id://715067]=note: print w/replies, xml ) Need Help??


in reply to Bitwise Operator Error

Your hexadecimal number in $testString needs to begin with 0x be properly interpreted as hexadecimal. Then it will work. You can also simplify your white-space removal. All together, here is one way to get where you want to go:
$testString =~ s/\s+//g;
$testString =~ s/^/0x/; $maskResult = $testString & 400000000000000000000000;
$maskResult = hex( $testString ) & 0x400000000000000000000000;

Updated: Need to use hex and need to have mask as hex string.

Updated 2: I see ikegami has also pointed out my error(s) corrected above.

Updated 3: and ikegami has also noted the need for Math::BigInt here.

Replies are listed 'Best First'.
Re^2: Bitwise Operator Error
by ikegami (Patriarch) on Oct 02, 2008 at 19:18 UTC

    That's wrong.

    >perl -we"print 0+'0x0001'" Argument "0x0001" isn't numeric in addition (+) at -e line 1. 0

    See my reply to the OP for details

Re^2: Bitwise Operator Error
by ravishi (Acolyte) on Oct 02, 2008 at 19:05 UTC
    Thanks for the help but I just tried what you suggested and it doesn't seem to work. It outputs a 0 which is correct but I get a warning saying that it isn't numeric. I then changed the first bit of the original string to an F to test if I get an output of 1, and I still get a 0.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://715067]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2025-01-23 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (67 votes). Check out past polls.