#!/usr/bin/perl -w use v5.14; my $x = <>; my $c = 0; my $p=16; while ($x) { if($x-$p>0){$c++;$x-=$p;} else {$p/=2} }