#### buf to integer?

```Hi All,

I am dealing with a Buf what includes 32 bit integers, but
they are entered somewhat backwards as view with hexedit:

AE 5D 5C 72 represents the number 725C5DAE

This is what I have come up with to convert this type of
number in a buffer to and integer

\$ p6 'my Buf \$x=Buf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=\$x[3] +< 0x18
+  \$x[2] +< 0x10  +  \$x[1] +< 0x08  +  \$x[0];  say \$x; say \$i.base(0x10);'

Buf:0x<ae 5d 5c 72>
725C5DAE

Is there a more "elegant" way to do this?

Many thanks,
-T
```
 0
perl6
2/8/2019 6:35:06 AM
perl.perl6.users 1192 articles. 0 followers.

13 Replies
86 Views

Similar Articles

[PageSpeed] 6

```--0000000000007b340f05815f83f0
Content-Type: text/plain; charset="UTF-8"

There's probably a nicer way but I don't generally play about with this
sort of thing.

:16([~] \$x.reverse.map( *.base(16) ))

It does involve lots of String manipulation, as I say. There's probably a
better way.

On Fri, 8 Feb 2019 at 06:35, Todd Chester via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> I am dealing with a Buf what includes 32 bit integers, but
> they are entered somewhat backwards as view with hexedit:
>
> AE 5D 5C 72 represents the number 725C5DAE
>
> This is what I have come up with to convert this type of
> number in a buffer to and integer
>
> \$ p6 'my Buf \$x=Buf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=\$x[3] +< 0x18
> +  \$x[2] +< 0x10  +  \$x[1] +< 0x08  +  \$x[0];  say \$x; say \$i.base(0x10);'
>
> Buf:0x<ae 5d 5c 72>
> 725C5DAE
>
>
> Is there a more "elegant" way to do this?
>
> Many thanks,
> -T
>

--
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/

--0000000000007b340f05815f83f0
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>There&#39;s probably a nicer way but I don&#39;t gene=
rally play about with this sort of thing.<br></div><div dir=3D"ltr"><br></d=
iv><div dir=3D"ltr">:16([~] \$x.reverse.map( *.base(16) ))</div><div dir=3D"=
ltr"><br></div><div>It does involve lots of String manipulation, as I say. =
There&#39;s probably a better way.<br></div><div dir=3D"ltr"><br></div></di=
v><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On F=
ri, 8 Feb 2019 at 06:35, Todd Chester via perl6-users &lt;<a href=3D"mailto=
:perl6-users@perl.org">perl6-users@perl.org</a>&gt; wrote:<br></div><blockq=
uote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1p=
<br>
I am dealing with a Buf what includes 32 bit integers, but<br>
they are entered somewhat backwards as view with hexedit:<br>
<br>
AE 5D 5C 72 represents the number 725C5DAE<br>
<br>
This is what I have come up with to convert this type of<br>
number in a buffer to and integer<br>
<br>
\$ p6 &#39;my Buf \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=3D\$x[3] +&l=
t; 0x18 <br>
+=C2=A0 \$x[2] +&lt; 0x10=C2=A0 +=C2=A0 \$x[1] +&lt; 0x08=C2=A0 +=C2=A0 \$x[0]=
;=C2=A0 say \$x; say \$i.base(0x10);&#39;<br>
<br>
Buf:0x&lt;ae 5d 5c 72&gt;<br>
725C5DAE<br>
<br>
<br>
Is there a more &quot;elegant&quot; way to do this?<br>
<br>
Many thanks,<br>
-T<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature">Simon Proctor<br>Cognoscite aliquid novum cotidie<br><br><a=
href=3D"http://www.khanate.co.uk/" target=3D"_blank">http://www.khanate.co=
..uk/</a></div>

--0000000000007b340f05815f83f0--
```
 0
simon
2/8/2019 10:34:59 AM
```--000000000000b7fa0b05815fda54
Content-Type: text/plain; charset="UTF-8"

On Fri, Feb 8, 2019 at 7:36 AM Todd Chester via perl6-users <
perl6-users@perl.org> wrote:

> I am dealing with a Buf what includes 32 bit integers, but
> they are entered somewhat backwards as view with hexedit:
>
> AE 5D 5C 72 represents the number 725C5DAE
>
> This is what I have come up with to convert this type of
> number in a buffer to and integer
>
> \$ p6 'my Buf \$x=Buf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=\$x[3] +< 0x18
> +  \$x[2] +< 0x10  +  \$x[1] +< 0x08  +  \$x[0];  say \$x; say \$i.base(0x10);'
>
> Buf:0x<ae 5d 5c 72>
> 725C5DAE
>
>
> Is there a more "elegant" way to do this?
>

The "elegant" way I'd do it, is using unpack():
https://docs.perl6.org/routine/unpack

It's experimental, so a declaration is needed, but Buf does Blob, so
otherwise, it's straight to the point:

\$ perl6 -e 'use experimental :pack; my Buf \$x=Buf.new(0xAE,0x5D,0x5C,0x72);
say \$x.unpack("L").base(0x10);'
725C5DAE
\$

Eirik

--000000000000b7fa0b05815fda54
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr">On Fri,=
Feb 8, 2019 at 7:36 AM Todd Chester via perl6-users &lt;<a href=3D"mailto:=
perl6-users@perl.org">perl6-users@perl.org</a>&gt; wrote:<br></div><div cla=
ss=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0p=
x 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I am d=
ealing with a Buf what includes 32 bit integers, but<br>
they are entered somewhat backwards as view with hexedit:<br>
<br>
AE 5D 5C 72 represents the number 725C5DAE<br>
<br>
This is what I have come up with to convert this type of<br>
number in a buffer to and integer<br>
<br>
\$ p6 &#39;my Buf \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=3D\$x[3] +&l=
t; 0x18 <br>
+=C2=A0 \$x[2] +&lt; 0x10=C2=A0 +=C2=A0 \$x[1] +&lt; 0x08=C2=A0 +=C2=A0 \$x[0]=
;=C2=A0 say \$x; say \$i.base(0x10);&#39;<br>
<br>
Buf:0x&lt;ae 5d 5c 72&gt;<br>
725C5DAE<br>
<br>
<br>
Is there a more &quot;elegant&quot; way to do this?<br></blockquote><div><b=
r></div><div>=C2=A0 The &quot;elegant&quot; way I&#39;d do it, is using unp=
ack(): <a href=3D"https://docs.perl6.org/routine/unpack">https://docs.perl6=
..org/routine/unpack</a></div><div><br></div><div>=C2=A0 It&#39;s experiment=
al, so a declaration is needed, but Buf does Blob, so otherwise, it&#39;s s=
traight to the point:</div><div><br></div><div>\$ perl6 -e &#39;use experime=
ntal :pack; my Buf \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72); say \$x.unpack(&quot;L=
&quot;).base(0x10);&#39;<br>725C5DAE<br>\$</div><div><br></div><div><br></di=
v><div>Eirik<br></div><div><br></div></div></div></div></div>

--000000000000b7fa0b05815fda54--
```
 0
sidhekin
2/8/2019 10:59:23 AM
```If you have a new enough version of Rakudo:

my Buf \$x=Buf.new(0xAE,0x5D,0x5C,0x72);

say \$i.base(16);
# 725C5DAE

On Fri, Feb 8, 2019 at 12:35 AM Todd Chester via perl6-users
<perl6-users@perl.org> wrote:
>
> Hi All,
>
> I am dealing with a Buf what includes 32 bit integers, but
> they are entered somewhat backwards as view with hexedit:
>
> AE 5D 5C 72 represents the number 725C5DAE
>
> This is what I have come up with to convert this type of
> number in a buffer to and integer
>
> \$ p6 'my Buf \$x=Buf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=\$x[3] +< 0x18
> +  \$x[2] +< 0x10  +  \$x[1] +< 0x08  +  \$x[0];  say \$x; say \$i.base(0x10);'
>
> Buf:0x<ae 5d 5c 72>
> 725C5DAE
>
>
> Is there a more "elegant" way to do this?
>
> Many thanks,
> -T
```
 0
b2gills
2/8/2019 5:54:51 PM
```--000000000000342f88058165ad0a
Content-Type: text/plain; charset="UTF-8"

Ooooooo. Nice.

On Fri, 8 Feb 2019, 17:55 Brad Gilbert <b2gills@gmail.com wrote:

> If you have a new enough version of Rakudo:
>
>     my Buf \$x=Buf.new(0xAE,0x5D,0x5C,0x72);
>
>     my int32 \$i = \$x.read-int32(0,LittleEndian);
>
>     say \$i.base(16);
>     # 725C5DAE
>
> On Fri, Feb 8, 2019 at 12:35 AM Todd Chester via perl6-users
> <perl6-users@perl.org> wrote:
> >
> > Hi All,
> >
> > I am dealing with a Buf what includes 32 bit integers, but
> > they are entered somewhat backwards as view with hexedit:
> >
> > AE 5D 5C 72 represents the number 725C5DAE
> >
> > This is what I have come up with to convert this type of
> > number in a buffer to and integer
> >
> > \$ p6 'my Buf \$x=Buf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=\$x[3] +< 0x18
> > +  \$x[2] +< 0x10  +  \$x[1] +< 0x08  +  \$x[0];  say \$x; say
> \$i.base(0x10);'
> >
> > Buf:0x<ae 5d 5c 72>
> > 725C5DAE
> >
> >
> > Is there a more "elegant" way to do this?
> >
> > Many thanks,
> > -T
>

Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">Ooooooo. Nice.</div><br><div class=3D"gmail_quote"><div d=
ir=3D"ltr">On Fri, 8 Feb 2019, 17:55 Brad Gilbert &lt;<a href=3D"mailto:b2g=
ills@gmail.com">b2gills@gmail.com</a> wrote:<br></div><blockquote class=3D"=
gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-=
left:1ex">If you have a new enough version of Rakudo:<br>
<br>
=C2=A0 =C2=A0 my Buf \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72);<br>
<br>
=C2=A0 =C2=A0 my int32 \$i =3D \$x.read-int32(0,LittleEndian);<br>
<br>
=C2=A0 =C2=A0 say \$i.base(16);<br>
=C2=A0 =C2=A0 # 725C5DAE<br>
<br>
On Fri, Feb 8, 2019 at 12:35 AM Todd Chester via perl6-users<br>
&lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank" rel=3D"norefe=
rrer">perl6-users@perl.org</a>&gt; wrote:<br>
&gt;<br>
&gt; Hi All,<br>
&gt;<br>
&gt; I am dealing with a Buf what includes 32 bit integers, but<br>
&gt; they are entered somewhat backwards as view with hexedit:<br>
&gt;<br>
&gt; AE 5D 5C 72 represents the number 725C5DAE<br>
&gt;<br>
&gt; This is what I have come up with to convert this type of<br>
&gt; number in a buffer to and integer<br>
&gt;<br>
&gt; \$ p6 &#39;my Buf \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=3D\$x[3=
] +&lt; 0x18<br>
&gt; +=C2=A0 \$x[2] +&lt; 0x10=C2=A0 +=C2=A0 \$x[1] +&lt; 0x08=C2=A0 +=C2=A0 =
\$x[0];=C2=A0 say \$x; say \$i.base(0x10);&#39;<br>
&gt;<br>
&gt; Buf:0x&lt;ae 5d 5c 72&gt;<br>
&gt; 725C5DAE<br>
&gt;<br>
&gt;<br>
&gt; Is there a more &quot;elegant&quot; way to do this?<br>
&gt;<br>
&gt; Many thanks,<br>
&gt; -T<br>
</blockquote></div>

```
 0
simon
2/8/2019 5:56:09 PM
```On 2/7/19 10:35 PM, Todd Chester via perl6-users wrote:
> Hi All,
>=20
> I am dealing with a Buf what includes 32 bit integers, but
> they are entered somewhat backwards as view with hexedit:
>=20
> AE 5D 5C 72 represents the number 725C5DAE
>=20
> This is what I have come up with to convert this type of
> number in a buffer to and integer
>=20
> \$ p6 'my Buf \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=3D\$x[3] +< =
0x18=20
> +=C2=A0 \$x[2] +< 0x10=C2=A0 +=C2=A0 \$x[1] +< 0x08=C2=A0 +=C2=A0 \$x[0];=C2=
=A0 say \$x; say \$i.base(0x10);'
>=20
> Buf:0x<ae 5d 5c 72>
> 725C5DAE
>=20
>=20
> Is there a more "elegant" way to do this?
>=20
> Many thanks,
> -T

Hi All,

Thank you for all the wonderful tips!  Now I have to
write them all down for my own documentation.

This is a fun one I also came up with.  Since I was already
doing bitwise shift left, I thought I might as well do
it all with bitwise operations: first bitwise shift left,
then bitwise OR to combine them.  (Yes, I played with AND
and OR gates 40 years ago.  CMOS was my favorite.)

\$ p6 'my Buf \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72);
my int32 \$i=3D\$x[3] +< 0x18  +|  \$x[2] +< 0x10  +|  \$x[1] +< 0x08 =

+|  \$x[0];
say \$x;
say \$i.base(0x10);'

Buf:0x<AE 5D 5C 72>
725C5DAE

Interesting that I did not have to put () to force the order of
operation.  "shift" came before "OR".

-T
```
 0
perl6
2/8/2019 7:20:39 PM
```On 2/8/19 2:34 AM, Simon Proctor wrote:
> There's probably a nicer way but I don't generally play about with this
> sort of thing.
>
> :16([~] \$x.reverse.map( *.base(16) ))
>
> It does involve lots of String manipulation, as I say. There's probably
> a better way.

Thank you!
```
 0
perl6
2/8/2019 7:27:11 PM
```On 2/8/19 2:59 AM, The Sidhekin wrote:

>  =C2=A0 The "elegant" way I'd do it, is using unpack():=20
> https://docs.perl6.org/routine/unpack
>=20
>  =C2=A0 It's experimental, so a declaration is needed, but Buf does Blo=
b, so=20
> otherwise, it's straight to the point:
>=20
> \$ perl6 -e 'use experimental :pack; my Buf=20
> \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72); say \$x.unpack("L").base(0x10);'
> 725C5DAE
> \$
>=20
>=20
> Eirik
>=20

Thank you!
```
 0
perl6
2/8/2019 7:28:29 PM
```On 2/8/19 9:54 AM, Brad Gilbert wrote:
> If you have a new enough version of Rakudo:
>
>      my Buf \$x=Buf.new(0xAE,0x5D,0x5C,0x72);
>
>      my int32 \$i = \$x.read-int32(0,LittleEndian);
>
>      say \$i.base(16);
>      # 725C5DAE

Thank you!
```
 0
perl6
2/8/2019 7:29:28 PM
```--00000000000070d500058168c5d8
Content-Type: text/plain; charset="UTF-8"

Unpack is very useful if you have multiple items you want to unpack, and if
you're familiar with the Perl 5 unpack then there's the P5pack module
(which isn't a full implementation of Perl 5's unpack, but is useful for
simpler things). If you want to unpack something from the middle of a Buf
or Blob then you'll need to explicitly skip over the beginning of the
buffer using "x", whereas read-int32 has an explicit position argument.

On Fri, 8 Feb 2019 at 22:00, The Sidhekin <sidhekin@gmail.com> wrote:

> On Fri, Feb 8, 2019 at 7:36 AM Todd Chester via perl6-users <
> perl6-users@perl.org> wrote:
>
>> I am dealing with a Buf what includes 32 bit integers, but
>> they are entered somewhat backwards as view with hexedit:
>>
>> AE 5D 5C 72 represents the number 725C5DAE
>>
>> This is what I have come up with to convert this type of
>> number in a buffer to and integer
>>
>> \$ p6 'my Buf \$x=Buf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=\$x[3] +< 0x18
>> +  \$x[2] +< 0x10  +  \$x[1] +< 0x08  +  \$x[0];  say \$x; say \$i.base(0x10);'
>>
>> Buf:0x<ae 5d 5c 72>
>> 725C5DAE
>>
>>
>> Is there a more "elegant" way to do this?
>>
>
>   The "elegant" way I'd do it, is using unpack():
> https://docs.perl6.org/routine/unpack
>
>   It's experimental, so a declaration is needed, but Buf does Blob, so
> otherwise, it's straight to the point:
>
> \$ perl6 -e 'use experimental :pack; my Buf
> \$x=Buf.new(0xAE,0x5D,0x5C,0x72); say \$x.unpack("L").base(0x10);'
> 725C5DAE
> \$
>
>
> Eirik
>
>

--00000000000070d500058168c5d8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Unpack is very useful if you have multiple items you want =
to unpack, and if you&#39;re familiar with the Perl 5 unpack then there&#39=
;s the P5pack module (which isn&#39;t a full implementation of Perl 5&#39;s=
unpack, but is useful for simpler things). If you want to unpack something=
from the middle of a Buf or Blob then you&#39;ll need to explicitly skip o=
ver the beginning of the buffer using &quot;x&quot;, whereas read-int32 has=
an explicit position argument.</div><br><div class=3D"gmail_quote"><div di=
r=3D"ltr" class=3D"gmail_attr">On Fri, 8 Feb 2019 at 22:00, The Sidhekin &l=
t;<a href=3D"mailto:sidhekin@gmail.com">sidhekin@gmail.com</a>&gt; wrote:<b=
r></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex=
<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr">On Fri, Feb 8, 2019 at 7=
:36 AM Todd Chester via perl6-users &lt;<a href=3D"mailto:perl6-users@perl.=
org" target=3D"_blank">perl6-users@perl.org</a>&gt; wrote:<br></div><div cl=
ass=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0=
px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I am =
dealing with a Buf what includes 32 bit integers, but<br>
they are entered somewhat backwards as view with hexedit:<br>
<br>
AE 5D 5C 72 represents the number 725C5DAE<br>
<br>
This is what I have come up with to convert this type of<br>
number in a buffer to and integer<br>
<br>
\$ p6 &#39;my Buf \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=3D\$x[3] +&l=
t; 0x18 <br>
+=C2=A0 \$x[2] +&lt; 0x10=C2=A0 +=C2=A0 \$x[1] +&lt; 0x08=C2=A0 +=C2=A0 \$x[0]=
;=C2=A0 say \$x; say \$i.base(0x10);&#39;<br>
<br>
Buf:0x&lt;ae 5d 5c 72&gt;<br>
725C5DAE<br>
<br>
<br>
Is there a more &quot;elegant&quot; way to do this?<br></blockquote><div><b=
r></div><div>=C2=A0 The &quot;elegant&quot; way I&#39;d do it, is using unp=
ack(): <a href=3D"https://docs.perl6.org/routine/unpack" target=3D"_blank">=
https://docs.perl6.org/routine/unpack</a></div><div><br></div><div>=C2=A0 I=
t&#39;s experimental, so a declaration is needed, but Buf does Blob, so oth=
erwise, it&#39;s straight to the point:</div><div><br></div><div>\$ perl6 -e=
&#39;use experimental :pack; my Buf \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72); say=
\$x.unpack(&quot;L&quot;).base(0x10);&#39;<br>725C5DAE<br>\$</div><div><br><=
/div><div><br></div><div>Eirik<br></div><div><br></div></div></div></div></=
div>
</blockquote></div>

--00000000000070d500058168c5d8--
```
 0
kevin
2/8/2019 9:37:40 PM
```On 2/8/19 1:37 PM, Kevin Pye wrote:
> Unpack is very useful if you have multiple items you want to unpack, an=
d=20
> if you're familiar with the Perl 5 unpack then there's the P5pack modul=
e=20
> (which isn't a full implementation of Perl 5's unpack, but is useful fo=
r=20
> simpler things). If you want to unpack something from the middle of a=20
> Buf or Blob then you'll need to explicitly skip over the beginning of=20
> the buffer using "x", whereas read-int32 has an explicit position argum=
ent.
>=20
> On Fri, 8 Feb 2019 at 22:00, The Sidhekin <sidhekin@gmail.com=20
> <mailto:sidhekin@gmail.com>> wrote:
>=20
>     On Fri, Feb 8, 2019 at 7:36 AM Todd Chester via perl6-users
>     <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>=20
>         I am dealing with a Buf what includes 32 bit integers, but
>         they are entered somewhat backwards as view with hexedit:
>=20
>         AE 5D 5C 72 represents the number 725C5DAE
>=20
>         This is what I have come up with to convert this type of
>         number in a buffer to and integer
>=20
>         \$ p6 'my Buf \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72); my int32 \$i=3D\$=
x[3]
>         +< 0x18
>         +=C2=A0 \$x[2] +< 0x10=C2=A0 +=C2=A0 \$x[1] +< 0x08=C2=A0 +=C2=A0=
\$x[0];=C2=A0 say \$x; say
>         \$i.base(0x10);'
>=20
>         Buf:0x<ae 5d 5c 72>
>         725C5DAE
>=20
>=20
>         Is there a more "elegant" way to do this?
>=20
>=20
>      =C2=A0 The "elegant" way I'd do it, is using unpack():
>     https://docs.perl6.org/routine/unpack
>=20
>      =C2=A0 It's experimental, so a declaration is needed, but Buf does=
Blob,
>     so otherwise, it's straight to the point:
>=20
>     \$ perl6 -e 'use experimental :pack; my Buf
>     \$x=3DBuf.new(0xAE,0x5D,0x5C,0x72); say \$x.unpack("L").base(0x10);'
>     725C5DAE
>     \$
>=20
>=20
>     Eirik
>=20

Interesting.  Thank you!
```
 0
perl6
2/8/2019 9:54:15 PM
```On 2/8/19 1:37 PM, Kevin Pye wrote:
> Unpack is very useful if you have multiple items you want to unpack, and
> if you're familiar with the Perl 5 unpack then there's the P5pack module
> (which isn't a full implementation of Perl 5's unpack, but is useful for
> simpler things). If you want to unpack so

I started using Perl at Perl 5.  I jumped to Perl 6 as soon as
I got a load of the sub routine declaration  clean up.  I write
in Top Down and live and die with subs.  Perl 5's sub declarations
are a pain in the ...

As far as my buf to integer problem, I will just write
a sub and use shift and OR.  Hmmm.   Top Down again.
Maybe I will make it into a module if I see myself using
it in other programs.  I worked a lot with AND and OR gates
many years ago and it brings back memories.
```
 0
perl6
2/9/2019 12:18:18 AM
```--0000000000001c135105816c6202
Content-Type: text/plain; charset="UTF-8"

the perl6-native "read-int32" or native-but-experimental "unpack" are the
natural answers- they map well from problem to answer! There's a good
example of perl6's pack in this thread.

read-int32 was mentioned without an example so...

my Buf \$x = Buf.new(0x00, 0xFF, 0x88, 0xAE,0x5D,0x5C,0x72);

Buf:0x<00 FF 88 AE 5D 5C 72>

===SORRY!=== Error while compiling:

Undeclared name:

LittleEndian used at line 1

Oh darn, need Perl6.d for read-int32 and the Endian enums! Is 6.d packaged
for general use?

-y

>
>

--0000000000001c135105816c6202
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div di=
r=3D"ltr"><div dir=3D"ltr">the perl6-native &quot;read-int32&quot; or nativ=
e-but-experimental &quot;unpack&quot; are the natural answers- they map wel=
l from problem to answer! There&#39;s a good example of perl6&#39;s pack in=
as mentioned without an example so...</div><div dir=3D"ltr"><span style=3D"=
background-color:rgb(255,255,255)"><br></span></div><div dir=3D"ltr"><p sty=
le=3D"margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font=
-family:Courier;color:rgb(59,35,34)"><span style=3D"font-variant-ligatures:=
no-common-ligatures;background-color:rgb(255,255,255)">my Buf \$x =3D Buf.ne=
w(0x00, 0xFF, 0x88, 0xAE,0x5D,0x5C,0x72);</span></p>
<p style=3D"margin:0px;font-stretch:normal;font-size:12px;line-height:norma=
l;font-family:Courier;color:rgb(59,35,34)"><span style=3D"font-variant-liga=
tures:no-common-ligatures;background-color:rgb(255,255,255)">Buf:0x&lt;00 F=
F 88 AE 5D 5C 72&gt;</span></p>
<p style=3D"margin:0px;font-stretch:normal;font-size:12px;line-height:norma=
l;font-family:Courier;color:rgb(59,35,34)"><span style=3D"font-variant-liga=
nt32(3,LittleEndian).base(0x10)</span></p>
<p style=3D"margin:0px;font-stretch:normal;font-size:12px;line-height:norma=
l;font-family:Courier;color:rgb(59,35,34)"><span style=3D"background-color:=
rgb(255,255,255)"><span style=3D"font-variant-ligatures:no-common-ligatures=
;color:rgb(159,20,16)">=3D=3D=3D</span><span style=3D"font-variant-ligature=
s:no-common-ligatures">SORRY!</span><span style=3D"font-variant-ligatures:n=
o-common-ligatures;color:rgb(159,20,16)">=3D=3D=3D</span><span style=3D"fon=
t-variant-ligatures:no-common-ligatures"> Error while compiling:</span></sp=
an></p>
<p style=3D"margin:0px;font-stretch:normal;font-size:12px;line-height:norma=
l;font-family:Courier;color:rgb(59,35,34)"><span style=3D"font-variant-liga=
tures:no-common-ligatures;background-color:rgb(255,255,255)">Undeclared nam=
e:</span></p>
<p style=3D"margin:0px;font-stretch:normal;font-size:12px;line-height:norma=
l;font-family:Courier;color:rgb(59,35,34)"><span style=3D"font-variant-liga=
tures:no-common-ligatures;background-color:rgb(255,255,255)">=C2=A0 =C2=A0 =
LittleEndian used at line 1</span></p></div><div dir=3D"ltr"><br></div><div=
>=C2=A0Oh darn, need Perl6.d for read-int32 and the Endian enums! Is 6.d pa=
ckaged for general use?</div><div><br></div><div dir=3D"ltr"><div><div dir=
=3D"ltr" class=3D"gmail_signature">-y<br></div></div></div><div class=3D"gm=
ail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.=
8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204=
</blockquote></div></div></div></div></div></div>

--0000000000001c135105816c6202--
```
 0
not
2/9/2019 1:56:14 AM
```The next release of Rakudo with have read-int32.

To use it now you would need to build from the git repository, I think.

On Fri, Feb 8, 2019 at 7:56 PM yary <not.com@gmail.com> wrote:
>
> the perl6-native "read-int32" or native-but-experimental "unpack" are the natural answers- they map well from problem to answer! There's a good example of perl6's pack in this thread.
>
> read-int32 was mentioned without an example so...
>
> my Buf \$x = Buf.new(0x00, 0xFF, 0x88, 0xAE,0x5D,0x5C,0x72);
>
> Buf:0x<00 FF 88 AE 5D 5C 72>
>
>
> ===SORRY!=== Error while compiling:
>
> Undeclared name:
>
>     LittleEndian used at line 1
>
>
>  Oh darn, need Perl6.d for read-int32 and the Endian enums! Is 6.d packaged for general use?
>
> -y
>>
>>
```
 0
b2gills
2/9/2019 4:47:08 AM