| Craig Rodgers 2007-03-29, 8:01 am |
| Hi,
Please bear with me for a bit, I'm not realy sure how to explaine my problem
so I'll try to give you an example of what's going wrong and what the
desired behaviour is.
I'm trying to calculate the CRC-8 checksum for the numbers 0~16 using the
Digest::CRC perl module.
The crc8 function takes a scalar input value and should return the crc
value.
It apears that the crc8 function uses the string representation of the
scalar value. Ie
printf ("%i,",crc8(0x01)) returns 144 which is the crc8 value of the
letter '1'.
printf ("%i,",crc8("\x01")); returns 7 which is the correct crc8
value for the number 1.
So far so good I hope.
The problem I'm having is that I'd like to make a simple loop to iterate
through the values I'd like to calculate the crc of.
use Digest::CRC qw(crc8);
foreach (0..16){
print("$_,");
printf ("%i,\n\r", crc8($_));
}
I've tried every possible combination and permitation of escape charaters,
adding "+ 0" to force a numeric conversion etc. To no avail.
I think what I want to do is to create a string that contains a single
character that consits of the binary value of my loop counter. Ie the string
[\x01] - the binary value of 1 as opposed to the ASCII/character value of
it.
Please any sugestions of how to perform such a task?
--------------------------------------------
Craig Rodgers
Snr Technical Officer (Electrical & Electronic Engineering)
Australian Centre for Field Robotics
The Rose St Building J04
The University of Sydney 2006, Australia
www.acfr.usyd.edu.au
Ph: +61-2-9036-6400
Fax: +61-2-9351-7474
Lab: +61-2-9036-6394
-------------------------------------------
|