Re: ones and twos compliment

2025-06-07 Thread Bruce Gray
> On Jun 6, 2025, at 21:53, ToddAndMargo via perl6-users > wrote: > > Hi All, > > Is there an easy way to print ones' and two's compliment > of a 32 bit integer? > > Many thanks, > -T > > > sub ones-complement(Int $num) { >my $binary = $num.base(2); >my $complement = ''; >for

Re: ones and twos compliment

2025-06-07 Thread ToddAndMargo via perl6-users
On 6/7/25 12:57 PM, Elizabeth Mattijsen wrote: On 7 Jun 2025, at 21:12, ToddAndMargo via perl6-users wrote: [0] > my int32 $y=-1073741510 -1073741510 [1] > my $ones-complement = +^$y; Bytecode validation error at offset 164, instruction 23: operand type 32 does not match register type 24 for o

Re: ones and twos compliment

2025-06-07 Thread Elizabeth Mattijsen
> On 7 Jun 2025, at 21:12, ToddAndMargo via perl6-users > wrote: > [0] > my int32 $y=-1073741510 > -1073741510 > > [1] > my $ones-complement = +^$y; > Bytecode validation error at offset 164, instruction 23: > operand type 32 does not match register type 24 for op getlex_ni in frame > > > [1]

Re: ones and twos compliment

2025-06-07 Thread ToddAndMargo via perl6-users
On Sat, Jun 7, 2025 at 4:53 AM ToddAndMargo via perl6-users wrote: Is there an easy way to print ones' and two's compliment of a 32 bit integer? Many thanks, -T On 6/7/25 10:22 AM, Paul Procacci wrote: > my $number = 42; > my $ones-complement = +^$number; > my $twos-complement = +^$number

Re: ones and twos compliment

2025-06-07 Thread Paul Procacci
my $number = 42; my $ones-complement = +^$number; my $twos-complement = +^$number + 1; ~Paul On Sat, Jun 7, 2025 at 11:26 AM Will Coleda wrote: > > (You may have to manually paste that URL, gmail cut off the trailing ^ here > when I clicked on my own link) > > On Sat, Jun 7, 2025 at 4:50 PM Wil

Re: ones and twos compliment

2025-06-07 Thread Will Coleda
(You may have to manually paste that URL, gmail cut off the trailing ^ here when I clicked on my own link) On Sat, Jun 7, 2025 at 4:50 PM Will Coleda wrote: > Two's complement (from google search of the docs site): > https://docs.raku.org/language/operators#prefix_+^ > > > > On Sat, Jun 7, 2025

Re: ones and twos compliment

2025-06-07 Thread Will Coleda
Two's complement (from google search of the docs site): https://docs.raku.org/language/operators#prefix_+^ On Sat, Jun 7, 2025 at 4:53 AM ToddAndMargo via perl6-users < perl6-us...@perl.org> wrote: > Hi All, > > Is there an easy way to print ones' and two's compliment > of a 32 bit integer? > >

ones and twos compliment

2025-06-06 Thread ToddAndMargo via perl6-users
Hi All, Is there an easy way to print ones' and two's compliment of a 32 bit integer? Many thanks, -T sub ones-complement(Int $num) { my $binary = $num.base(2); my $complement = ''; for $binary.comb -> $bit { $complement ~= $bit eq '0' ?? '1' !! '0'; } return $compl