My question is short. I'm trying to use perl to do some bitwise operations. The numbers are large, so I thought it would be nice to use the "string" bitwise AND (that is on page 102 in the 3rd edition of the camel BTW). I have two problems with it though. Here is some example code of the two problems:
#!/usr/local/bin/perl -w
use strict;
my $key = "24" & "4";
print "Key: $key\n";
my $key2 = "2f" & "4";
print "Key2: $key2\n";
my $key3 = "24" & "04";
print "Key3: $key3\n";
But that outputs:
Key: 0
Key2: 0
Key3: 04
So really only the last case works. It says right in the camel book that it should assume the string is padded with zeros if one string is longer than the other. Also, why on earth can I not use hex digits in this type of operation?
I guess I'm just really frustrated by perls bitwise funcitonality right now. It sure seems difficult to deal with things as bits to me. Anyone know of a good tutorial on this type of thing?
Justin Eltoft
"If at all god's gaze upon us falls, its with a mischievous grin, look at him" -- Dave Matthews
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.