Your skill will accomplish what the force of many cannot |
|
PerlMonks |
pack and unpack with 8 bit integersby thanos1983 (Parson) |
on Sep 22, 2014 at 10:54 UTC ( [id://1101500]=perlquestion: print w/replies, xml ) | Need Help?? |
thanos1983 has asked for the wisdom of the Perl Monks concerning the following question: Hello Monks, Update: Title update from (How to convert an integer 8bit long to binary and vice versa) to (pack and unpack with 8 bit integers). Lately I have been asking way too many questions, apologies for that. Although that I thought that I was starting to get the conversion process of decimal to binary and binary to decimal, I got stack again. I want to convert an integer 8 bit long with template format "i" to binary and then convert it pack to decimal with the same format "i". I want to complete the process using pack and unpack. I have been experimenting with a sample of code. I can not figure it out why is not working properly. Sample of code:
I have broken down the process into pieces in order to detect the error. It seems the error comes from the pack process. So at this point I can not understand why. I have found a way to by avoid the error by modifying the $template on the sub bin2dec process from "i" (intiger) to "c" (8 bit character). By doing so I get the correct output, but since I am defining B8 I should not have a problem with the unpack process. So can someone help me understand where I am going wrong, and how to fix my problem? Thanks in advance for everyone's time and effort to assist me.
Seeking for Perl wisdom...on the process of learning...not there...yet!
Back to
Seekers of Perl Wisdom
|
|