anadem has asked for the wisdom of the Perl Monks concerning the following question:
Using the neat Win32::TieRegistry module I'm reading stuff from the Windows registry. The data gets written to a file, which is later read and processed. I'm having trouble with bit-twiddling after reading the data file, because of my limited understanding of pack, unpack and perl's internal data representation. I'm just missing something here -- possibly a piece of grey matter.
We're using ActiveState perl: "This is perl, version 5.005_03 built for MSWin32-x86-object" (but will probably be moving to a newer version soon.)
For REG_DWORD items read by Win32::TieRegistry's GetValue, the value is read thus:
So for a reg_dword value 0x00500000 in the registry, the string 5242880 is written to file.my ( $value, $type ) = $key->GetValue( "$_" ); # ---- format the value as text if ( $type == 4 ) # reg_dword { $value = hex( $value ) }
Later I want to test and set bits in the value against a mask, so presumably it needs to be packed back into four bytes. Unfortunately none of my attempts to do this work, and I can't figure out how to "see" how perl is storing the data. Please can someone who has seen the light tell me how?
maybe something like this:
Many thanks$dword = pack <somehow> ( $value ); # eg $value = 5242880 dec $mask = pack <somehow> ( 4194304 ); # 0x00400000 $flags = pack <somehow> ( 1048576 ); # 0x00100000 $testdw = $dword & $mask; $newdw = $dword | $flags; $newval = hex ( $newdw ); # gets written to file
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to pack bits, flags and masks
by Zaxo (Archbishop) on Nov 15, 2004 at 18:42 UTC | |
by anadem (Scribe) on Nov 15, 2004 at 19:18 UTC | |
by ikegami (Patriarch) on Nov 15, 2004 at 19:51 UTC | |
|
Re: how to pack bits, flags and masks
by jimbojones (Friar) on Nov 15, 2004 at 19:04 UTC |