Re: How do I convert integer to cardinal on the fly?

2020-01-08 Thread ToddAndMargo via perl6-users

On 2020-01-07 08:20, ToddAndMargo via perl6-users wrote:

On 2020-01-06 22:54, ToddAndMargo via perl6-users wrote:

Hi All,

What am I doing wrong here?

 > my int16 $x = 0xABCD;
-21555

 > say $x.base(16);
-5433

 > my uint16 $y = $x.uint16;
No such method 'uint16' for invocant of type 'Int'
   in block  at  line 1

Many thanks,
-T



Came up with a work around:

  my int16 $x = 0xABCD;
  my uint16 $y = $x +| 0x;
  say $x.base(16);
  say $y.base(16)

  -5433
  ABCD

What is the proper way?


Follow up:

One of the developers on the chat line just verified
for me that my workaround it the only way to do it.


Re: How do I convert integer to cardinal on the fly?

2020-01-07 Thread Todd Chester via perl6-users
On Tue, Jan 7, 2020 at 10:20 AM ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:


On 2020-01-06 22:54, ToddAndMargo via perl6-users wrote:
 > Hi All,
 >
 > What am I doing wrong here?
 >
 >  > my int16 $x = 0xABCD;
 > -21555
 >
 >  > say $x.base(16);
 > -5433
 >
 >  > my uint16 $y = $x.uint16;
 > No such method 'uint16' for invocant of type 'Int'
 >in block  at  line 1
 >
 > Many thanks,
 > -T


Came up with a work around:

   my int16 $x = 0xABCD;
   my uint16 $y = $x +| 0x;
   say $x.base(16);
   say $y.base(16)

   -5433
   ABCD

What is the proper way?





On 2020-01-07 08:33, Brad Gilbert wrote:

       my int16 $x = 0xABCD;
       my uint16 $y = $x;

       say $x.base(16);
       say $y.base(16)

       -5433
       ABCD

If you just want to coerce to uint16

     (my uint16 $ = $x)

     say (my uint16 $ = $x).base(16)



I was looking for a way to do it after the variables were declared


Re: How do I convert integer to cardinal on the fly?

2020-01-07 Thread Brad Gilbert
  my int16 $x = 0xABCD;
  my uint16 $y = $x;

  say $x.base(16);
  say $y.base(16)

  -5433
  ABCD

If you just want to coerce to uint16

(my uint16 $ = $x)

say (my uint16 $ = $x).base(16)

On Tue, Jan 7, 2020 at 10:20 AM ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-01-06 22:54, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > What am I doing wrong here?
> >
> >  > my int16 $x = 0xABCD;
> > -21555
> >
> >  > say $x.base(16);
> > -5433
> >
> >  > my uint16 $y = $x.uint16;
> > No such method 'uint16' for invocant of type 'Int'
> >in block  at  line 1
> >
> > Many thanks,
> > -T
>
>
> Came up with a work around:
>
>   my int16 $x = 0xABCD;
>   my uint16 $y = $x +| 0x;
>   say $x.base(16);
>   say $y.base(16)
>
>   -5433
>   ABCD
>
> What is the proper way?
>


Re: How do I convert integer to cardinal on the fly?

2020-01-07 Thread ToddAndMargo via perl6-users

On 2020-01-06 22:54, ToddAndMargo via perl6-users wrote:

Hi All,

What am I doing wrong here?

 > my int16 $x = 0xABCD;
-21555

 > say $x.base(16);
-5433

 > my uint16 $y = $x.uint16;
No such method 'uint16' for invocant of type 'Int'
   in block  at  line 1

Many thanks,
-T



Came up with a work around:

 my int16 $x = 0xABCD;
 my uint16 $y = $x +| 0x;
 say $x.base(16);
 say $y.base(16)

 -5433
 ABCD

What is the proper way?


How do I convert integer to cardinal on the fly?

2020-01-06 Thread ToddAndMargo via perl6-users

Hi All,

What am I doing wrong here?

> my int16 $x = 0xABCD;
-21555

> say $x.base(16);
-5433

> my uint16 $y = $x.uint16;
No such method 'uint16' for invocant of type 'Int'
  in block  at  line 1

Many thanks,
-T