Google is your friend. The substantive portion is lifted nearly verbatim from onperl.net's binary arithmetic tut. NB You'll have work to do to extend this beyond 0b111.
C:\>perl -E "my $result = 0b01011/0b11; say $result;"
3.66666666666667 # output in decimal.
for binary output:
#! /usr/bin/perl
use 5.014;
my @CONVERSIONS = qw(000 001 010 011 100 101 110 111);
sub conv2bin{
my $octal = sprintf ("%o", $_[0]);
my @threeBitSeqs = map {$CONVERSIONS [$_]} (split //, $octal);
return (join "", @threeBitSeqs);
}
my $result = 0b01011/0b11;
say "decimal: $result";
my $bin= conv2bin($result);
say "binary: $bin";
=head
D:\>perl bin_div.pl
decimal: 3.66666666666667
binary: 011 # 3 decimal (or 3.66667 truncated) expressed as binar
+y.
# Now, try this dividing -- oh, say, 6dec by 2dec...
=cut
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|