in reply to using vec() and unpack()
Hmm...you're absolutely right. However, let's take a look at what it is printing out.
With your unpack, you are specifying b which means that the left-most bit is least significant. So what does 10001100 become? 49. What's 49? It is the ascii code for 1. If you change your unpack to "b*", @charBits contains 24 elements and looks like: 100011000100110001101100. Taken in 8 bit chunks, it turns out to be 49, 50, 54 (the ascii codes for 1, 2 and 6).
Please remember that unpack thinks whatever you give it is a string. To fix your problem, all you need to do is first pack your 126 as an integer like so: my @charBits = split(//, unpack('b8', pack("S",$temp)));. Now the code should works as expected (it should print 01111110). Please check out perlpacktut for more information.
Hope this helps.
antirice
The first rule of Perl club is - use Perl
The ith rule of Perl club is - follow rule i - 1 for i > 1
|
|---|