Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Split any number into string of 8-bit hex values (=1 byte)

by Marshall (Canon)
on Aug 30, 2021 at 10:56 UTC ( [id://11136201]=note: print w/replies, xml ) Need Help??


in reply to Re: Split any number into string of 8-bit hex values (=1 byte)
in thread Split any number into string of 8-bit hex values (=1 byte)

Your regex code is impressive to say the least!
It replicates my output verbatim.

But this fuzzy requirement about the number of bytes to be output seems odd to me.
I updated my post with what I hope is a clear question to the OP.

I guess we shall see what, if anything develops from that.

  • Comment on Re^2: Split any number into string of 8-bit hex values (=1 byte)

Replies are listed 'Best First'.
Re^3: Split any number into string of 8-bit hex values (=1 byte)
by tybalt89 (Monsignor) on Aug 30, 2021 at 13:34 UTC

    I do have another regex ready in case the OP wants answers that are ONLY 1, 2, 4, or 8 bytes long.

    We'll just have to wait...

      Yes please :-) If I'd convert anything from a quad and then remove unnecessary leading zeros so that I'd end up with 1, 2, 4 or 8 bytes I'm thinking that this should work. What does the regex look like?
        #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11136191 use warnings; for my $n (0, 2, 20, 200, 2000, 20000, 200000) { my @bytes = reverse sprintf('%016X', $n) =~ s/^0{8}(0{4}(00)?)?//r = +~ /../g; print "$n => @bytes\n"; }

        Outputs:

        0 => 00 2 => 02 20 => 14 200 => C8 2000 => D0 07 20000 => 20 4E 200000 => 40 0D 03 00

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2024-04-18 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found