Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Unpacking byte stream long/quad little/big endian fields

by xiaoyafeng (Deacon)
on Jan 25, 2021 at 08:00 UTC ( [id://11127431]=note: print w/replies, xml ) Need Help??


in reply to Unpacking byte stream long/quad little/big endian fields

if you treat this everyday, the better way is to create a template:

use strict; use warnings; use Convert::Binary::C; use Data::Dumper; use Data::Hexdumper; my $c = Convert::Binary::C->new(ByteOrder => 'BigEndian', LongSize => + 8)->parse(<<'ENDC'); struct one8 { unsigned long a; }; struct two4 { unsigned int a; unsigned int b; }; ENDC my $data = "\x91\x34\x33\x90\x81\x32\x31\x80"; print hexdump($data); print "BigEndian\n"; my $u1 = $c->unpack('one8', $data); print Dumper $u1; my $u2 = $c->unpack('two4', $data); print Dumper $u2; print "LittleEndian\n"; $c->tag('one8', ByteOrder => 'LittleEndian'); $c->tag('two4', ByteOrder => 'LittleEndian'); my $u3 = $c->unpack('one8', $data); print Dumper $u3; my $u4 = $c->unpack('two4', $data); print Dumper $u4;




I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11127431]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-24 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found