Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Constructing 32-bit hexadecimal integers

by satchboost (Scribe)
on Apr 11, 2001 at 23:40 UTC ( [id://71829]=note: print w/replies, xml ) Need Help??


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")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://71829]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-24 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found