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

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

by LanX (Sage)
on Aug 30, 2021 at 21:32 UTC ( #11136255=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)

> However, I don't need perl to know the type of number it needs to convert.

that doesn't sound right ...

If you have the value 2 which has to be put into a long register as 00 00 00 02 how is Perl supposed to guess that 4 bytes are needed and 02 isn't already sufficient?

But if your transfer protocol was able to handle 02 for a long register, why would anyone need to stuff any leading/trailing 0s into it?

The straight mathematical way to tell the "width" of a number is using log like already shown. But given your demonstrated code I'd rather suggest you sticking with 3 if-then-else levels inside a sub.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2021-12-03 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (30 votes). Check out past polls.

    Notices?