in reply to Constructing 32-bit hexadecimal integers

try something like:
my $first = 0x2d; my $second = 0x05; my $string = sprintf("%02X%02X", hex($first), hex($second));

The basic idea is to sprintf() them, then concatenate the resultant strings.

Replies are listed 'Best First'.
Re: Re: Constructing 32-bit hexadecimal integers
by donfreenut (Sexton) on Apr 11, 2001 at 23:52 UTC

    I didn't explain this very clearly, sorry.

    A set of 1, 2, 3 or 4 hex values are stored in one variable. If you printed the variable, you'd get whatever ASCII characters corresponded to the hex values. (There's probably a better way to explain this, but I don't really speak the language quite yet.)

    Should I split() the variable, then sprintf, then concatenate?

    Thanks once more...

    ---
    donfreenut
      Nah, use unpack at will.

      You will have to pad them missing values:

      $a = "\001"; #just another hex string $a = ("\000" x (4-length($a))).$a; #Zero pad that string print unpack 'L', $a; #Hey, that's one!

      Jeroen
      "We are not alone"(FZ)

        Well, it is either 1 or 0x01000000, depending on your platform. Use 'N' or 'V' in place of 'L' if you want to use big- or little-endian format (respectively) regardless of your current platform.

                - tye (but my friends call me "Tye")