in reply to Bitwise Operator Error
Strings used in numerical context as treated as decimal numbers. Use hex to convert them
Similarly, numerical literals are treated as decimal numbers. Prepend 0x.
#!/usr/bin/perl -w # File displayPipeTracer2.pl my $testString = " 00008008 000000FF 00800000"; $testString =~ s/\s+//g; my $maskResult = hex($testString) & 0x400000000000000000000000; print "Mask Result: $maskResult\n";
But those numbers are huge!
Integer overflow in hexadecimal number at script.pl line 7. Hexadecimal number > 0xffffffff non-portable at script.pl line 7. Integer overflow in hexadecimal number at script.pl line 7. Hexadecimal number > 0xffffffff non-portable at script.pl line 7. Mask Result: 4294967295
But Perl is capable of large number arithmetic using bigint/Math::BigInt.
#!/usr/bin/perl -w # File displayPipeTracer2.pl use bigint; my $testString = " 00008008 000000FF 00800000"; $testString =~ s/\s+//g; $testString = Math::BigInt->new("0x$testString"); my $maskResult = $testString & 0x400000000000000000000000; print "Mask Result: $maskResult\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Bitwise Operator Error
by ravishi (Acolyte) on Oct 03, 2008 at 13:35 UTC | |
by ikegami (Patriarch) on Oct 03, 2008 at 19:53 UTC |
In Section
Seekers of Perl Wisdom