good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Pack + Fat32 timestamp (|, <<)by tye (Sage) |
on Jul 25, 2015 at 22:57 UTC ( [id://1136315]=note: print w/replies, xml ) | Need Help?? |
pack is the wrong function for what you are trying to do, for two reasons. First, pack() really doesn't deal with things smaller than bytes (which is not completely obvious from the documentation). Second, pack() gives you a string whose bytes represent binary values in various formats and what you want is a numeric value expressed as hexademical. Putting the bits together into a numeric value is much closer to your working extraction code but using | instead of & and << instead of >>:
Update: Another approach is to use a base-2 string of '0' and '1' characters, using Perl's support for numbers like 0b10011 (also via oct) and sprintf's %b format, like so:
Here is example data from testing those two snippets:
- tye
In Section
Seekers of Perl Wisdom
|
|