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 wrote:
>
> the perl6-native "read-int32" or native-but-experimental "unpack" are the
> natural answers- they map well from problem to
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);
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
is 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
g> 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
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!
On 2/8/19 2:59 AM, The Sidhekin wrote:
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
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!
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
725C5DAE
Is there a more "elegant" way to do this?
Many thanks,
-T
Hi All,
Thank you for all
; >
> > 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
> > 725C5DAE
> >
> >
> > Is there a more "elegant" way to do this?
> >
> > Many thanks,
> > -T
>
h 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(0x
s 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
> 725C5DAE
>
>
&
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 buffe
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
14 matches
Mail list logo