So here's the problem:
I have a hex string that is 104 bits. I need to shift the string 1 bit to the left (thus it will be 105 bits) add 1, and convert the result back into hex. Here's the code I have so far (and yes I know, I should have used strict and warnings):
sub shift_bs{ %cs0=( '0' => '0', '1' => '2', '2' => '4', '3' => '6', '4' => '8', '5' => 'A', '6' => 'C', '7' => 'E', '8' => '0', '9' => '2', 'a' => '4', 'b' => '6', 'c' => '8', 'd' => 'A', 'e' => 'C', 'f' => 'E' ); %cs1=( '0' => '1', '1' => '3', '2' => '5', '3' => '7', '4' => '9', '5' => 'B', '6' => 'D', '7' => 'F', '8' => '1', '9' => '3', 'a' => '5', 'b' => '7', 'c' => '9', 'd' => 'B', 'e' => 'D', 'f' => 'F' ); $c1 = shift; $char_stream = shift; if($char_stream =~ /^$/){ return $c1; } $char_stream =~ /^(.*)(.)$/; ($char_st,$char)=($1,$2); $c_ = int(hex($char)/8); $char2=($c1==1?$cs1{$char}:$cs0{$char}); return ((shift_bs($c_,$char_st)).$char2); }
The call to this sub is:
push @src, shift_bs(1,$source);
Where $source is the hex string that I'm trying to convert.

The problem is, I get nothing back. Any help would be apprecated. Oh, and for those wondering why I'm not using Math::BigInt, this script will be distributed, and it is likely that atleast one machine won't have that on it. (And as always, it is just as likely we'll discover that the machine is lacking this module when it is too late to fix it.)
==
Kwyjibo. A big, dumb, balding North American ape. With no chin.

In reply to Bit by a Hex String by abitkin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.