Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
XP is just a number
 
PerlMonks  

Re: Picking certain values to convert from binary to decimal

by Zaxo (Archbishop)
on Jan 03, 2004 at 14:53 UTC ( [id://318530]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Picking certain values to convert from binary to decimal

If I understand correctly, you want to extract the three bytes starting at offset 29. You can get those with substr and then unpack them. Since your file is binary, let's read the first 32 bytes only, by setting $/ to a reference to 32.

my @chars; { local $/ = \32; open my $fh, '<', $name or die $!; binmode $fh; local $_ = <$fh>; @chars = unpack 'CCC', substr $_, 29, 3; close $fh or die $!; } print "@chars", $/; # quoted only to put space between values
The conversion is done by unpack, according to the template given in its first argument. "Decimal" really has little to do with it. The decimal string is produced by the stringification of a numeric value.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Picking certain values to convert from binary to decimal
by nadadogg (Acolyte) on Jan 08, 2004 at 09:51 UTC
    This output values similar to what I used before, and even though I found an alternate way of doing it(using some proprietary work stuff), your stuff helped me understand how to use it. Thanks a bunch.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://318530]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.