On 3/14/07, Dharshana Eswaran <[EMAIL PROTECTED]> wrote:
snip
> The data which i need to pack and unpack to these elements are in hex
> format(0x0B 0x1C 0x34 etc). It is a string of hex bytes.
>

Can i know about the format in which i need to supply the input? Coz i am
unable to accept the hex string.

Thanks and Regards,
Dharshana

Is "0x0B 0x1C 0x34" the actual form of your data?  If so, then you do
not probably want to use pack, in that case split, map, and hex are
your friends:

$input = however_you_get_your_input();
my @bytes = map { hex } split ' ', $input;
die "$_ is not a byte" unless $_ >= 0 and $_ <= 255 for @bytes;

If you have a total of six bytes then they are outputing the enum with
two bytes, so you need to determine which order it is in (big endian
or little endian).
my $callId = $bytes[0];
my $type  = $bytes[1] <<8 | $bytes[2]; #or $bytes[2] <<8 | $bytes[1];
my $phonenumber = $bytes[3];
my $lineno = $bytes[4] <= 127 ? $bytes[4] : -256 + $bytes[4]; #handle sign
my $alpha = $bytes[5]

If you only have five bytes then they are treating the enum as a one
byte field due to the fact that they know (or hope) it will never be
larger than 255:
my $callId = $bytes[0];
my $type  = $bytes[1];
my $phonenumber = $bytes[2];
my $lineno = $bytes[3] <= 127 ? $bytes[3] : -256 + $bytes[3]; #handle sign
my $alpha = $bytes[4]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to