Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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

by xiaoyafeng (Deacon)
on Jan 25, 2021 at 08:00 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2023-03-21 17:22 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.