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