Re: buf to integer?

2019-02-08 Thread Brad Gilbert
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

Re: buf to integer?

2019-02-08 Thread yary
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);

Re: buf to integer?

2019-02-08 Thread ToddAndMargo via perl6-users
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

Re: buf to integer?

2019-02-08 Thread ToddAndMargo via perl6-users
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

Re: buf to integer?

2019-02-08 Thread Kevin Pye
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

Re: buf to integer?

2019-02-08 Thread ToddAndMargo via perl6-users
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!

Re: buf to integer?

2019-02-08 Thread ToddAndMargo via perl6-users
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

Re: buf to integer?

2019-02-08 Thread ToddAndMargo via perl6-users
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!

Re: buf to integer?

2019-02-08 Thread ToddAndMargo via perl6-users
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

Re: buf to integer?

2019-02-08 Thread Simon Proctor
; > > > 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 >

Re: buf to integer?

2019-02-08 Thread Brad Gilbert
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

Re: buf to integer?

2019-02-08 Thread The Sidhekin
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 > > &

Re: buf to integer?

2019-02-08 Thread Simon Proctor
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

buf to integer?

2019-02-07 Thread Todd Chester via perl6-users
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