my $number = 42;
my $ones-complement = +^$number;
my $twos-complement = +^$number + 1;

~Paul

On Sat, Jun 7, 2025 at 11:26 AM Will Coleda <w...@coleda.com> 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 Will Coleda <w...@coleda.com> wrote:
>>
>> 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?
>>>
>>> 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 $complement;
>>> }
>>>
>>> my $number = 5;
>>> my $complement = ones-complement($number);
>>> print "Ones complement of $number is $complement\n";
>>>
>>>
>>> seems a bit much:
>>> https://search.brave.com/search?q=raku+print+ones+compliment&source=web&summary=1&conversation=00fda578d0badafdf15143



-- 
__________________

:(){ :|:& };:

Reply via email to