Blog of Leonid Mamchenkov

You just stepped in a pile of posts.

Entries Tagged as 'convertion'

Decimal to binary convertion in Perl

Posted in All on January 26th, 2006 · 3 Comments

This is a simple thing, but when you need it - you need it. There is no need in implementing a function that does or looking for a module at CPAN. All you are looking for is already there.

#!/usr/bin/perl -w

use strict;

# Get the number from the command line or use default.
my $number = shift || 42;

printf "%b\n", $number;

You might want to refresh you memory of printf or sprintf by flipping though the manual pages.

P.S.: 42 decimal = 101010 binary. Is it cool or what?

→ 3 CommentsTags: , , , , , , ,