Hi

I'm confused. Why can't you just leave everything in Perl's internal format?

#-- set up the vars to be like what Win32::TieRegistry returns (a stri +ng and a number); my ($dword, $type) = ( '0x00500000', 4); if ( $type == 4 ) { $dword = hex $dword; } printf "Dword:\tdec:%d\thex:%x\n", $dword, $dword; my $mask = 0x00400000; printf "mask:\tdec:%d\thex:%x\n", $mask, $mask; my $flags = 0x00100000; printf "mask:\tdec:%d\thex:%x\n", $flags, $flags; my $testdw = $dword & $mask; my $newdw = $dword | $flags; printf "TestDW:\tdec:%d\thex:%x\n", $testdw, $testdw; printf "NewDW:\tdec:%d\thex:%x\n", $newdw, $newdw;
Results

Dword: dec:5242880 hex:500000 mask: dec:4194304 hex:400000 mask: dec:1048576 hex:100000 TestDW: dec:4194304 hex:400000 NewDW: dec:5242880 hex:500000
I think you still need the first $dword = hex $dword; as the return from Win32::TieRegistry is a string.

- j

In reply to Re: how to pack bits, flags and masks by jimbojones
in thread how to pack bits, flags and masks by anadem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.