Snippets

Brian Medley Kibbles 'n bits

Created by Brian Medley
#!/opt/perl

use strict;
use warnings;

use feature qw(say);

my @values = (1, 0, 1, 1);

my $value = 0;

for (my ($idx, $pw) = ($#values, 0); $idx >= 0; --$idx, ++$pw) {
    # warn(sprintf("idx: $idx: [idx]: $values[$idx]: %s", 2 ** $idx));
    $value += $values[$idx] * (2 ** $pw);
}

say($value);

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.