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
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

Re: buf to integer?

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

Re: buf to integer?

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

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
On 2/7/19 10:35 PM, Todd Chester via perl6-users 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

Re: shift left syntax?

2019-02-08 Thread ToddAndMargo via perl6-users
>> >> Hi All, >> >> Is this the only way to shift left? >> >> $i = $i +< 0x01 >> >> $ p6 'my int32 $i=0x5DAE; say $i.base(0x10); $i = $i +< 0x01; say >> $i.base(0x10);' >> >> 5DAE >> BB5C >> >> >> Does we have any of those fancy += ~= ways of doing it? >> >> Many thanks, >> -T On

Re: shift left syntax?

2019-02-08 Thread Brad Gilbert
The `=` infix operator is a meta operator. That means it takes an infix operator as a sort of "argument". There is no `+=` operator, it is just the `=` operator combined with the `+` operator. $a += 2; $a [+]= 2; # more explicitly take the + operator as an argument to the = operator So

Re: buf to integer?

2019-02-08 Thread Simon Proctor
Ooo. Nice. On Fri, 8 Feb 2019, 17:55 Brad Gilbert 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

Re: buf to integer?

2019-02-08 Thread Brad Gilbert
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 wrote: > > Hi All, > > I am dealing with a Buf what

Re: buf to integer?

2019-02-08 Thread The Sidhekin
On Fri, Feb 8, 2019 at 7:36 AM Todd Chester via perl6-users < perl6-us...@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

Re: buf to integer?

2019-02-08 Thread Simon Proctor
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-us...@perl.org>