Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Help me decipher code containing map function

by Anonymous Monk
on May 20, 2017 at 19:45 UTC ( [id://1190744]=note: print w/replies, xml ) Need Help??


in reply to Re: Help me decipher code containing map function
in thread Help me decipher code containing map function

why (H2)* and not H* ?
  • Comment on Re^2: Help me decipher code containing map function

Replies are listed 'Best First'.
Re^3: Help me decipher code containing map function
by AnomalousMonk (Archbishop) on May 20, 2017 at 21:58 UTC

    Because  H* gives you a single string of an unlimited number, necessarily even, of hex characters, but  (H2)* gives you an unlimited number of groups of pairs (or in the case of  (H4)* quartets). The parentheses do grouping in pack/unpack templates. The groups can be quantified. BTW: This is susceptible to experimentation:

    c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $octetstr = qq{\xab\xcd\x00\x1d\x94\x56}; ;; my @ra = unpack 'H*', $octetstr; dd \@ra; ;; @ra = unpack '(H2)*', $octetstr; dd \@ra; ;; @ra = unpack '(H4)*', $octetstr; dd \@ra; " ["abcd001d9456"] ["ab", "cd", "00", "1d", 94, 56] ["abcd", "001d", 9456]


    Give a man a fish:  <%-{-{-{-<

Re^3: Help me decipher code containing map function
by afoken (Chancellor) on May 20, 2017 at 19:46 UTC

    Because an even number of hex digits (H) is needed.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^3: Help me decipher code containing map function
by BrowserUk (Patriarch) on May 20, 2017 at 22:04 UTC

    Because bytes (pompously aka. octets) consist of 2 hex digits dec:0 -> 0x00 dec:255 -> 0xff.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

      The octet term is commonly used in networking, RFC's, etc. It designates an 8-bit unit.

      A byte is generally 8 bits, too, although some historical computers had 9-bit bytes (and 36-bit words). There might be some uses for wide character definition today as well, as there are architectures where memory is word-addressable.

      I suppose the writers of standards and documentation prefer not to get sidetracked with moot issues in terminology, hence the unambiguous "octet".

        The byte (/ˈbaɪt/) is a unit of digital information that most commonly consists of eight bits. Historically, .... The modern de-facto standard of eight bits, as documented in ISO/IEC 2382-1:1993, is a convenient power of two permitting the values 0 through 255 for one byte.5 The international standard IEC 80000-13 codified this common meaning. Many types of applications use information representable in eight or fewer bits and processor designers optimize for this common usage. The popularity of major commercial computing architectures has aided in the ubiquitous acceptance of the eight-bit size

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
        In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-11-14 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    chatterbot is...






    Results (39 votes). Check out past polls.