Binary?!

So, my son asked me yesterday about how computers work, and we finally got to binary, which he had heard about in school. Then he asks me how numbers look like in binary, and stuff like that. Instead of looking them up, I came up with a perl script to show him any number he would want to see in binary. It’s nothing earth-shattering, but I thought someone may want get a kick out of it, and it really shows how powerful perl is. So, here goes:

#!/usr/bin/perl -w

use strict;

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

printf "%b\n", $number;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s