Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: built in function for binary division

by ww (Archbishop)
on Jan 11, 2013 at 05:46 UTC ( #1012799=note: print w/replies, xml ) Need Help??


in reply to built in function for binary division

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1012799]
help
Chatterbox?
[TStanley]: I'm sitting in the airport in Tampa, Florida at the moment, getting ready to head home.
[talexb]: TStanley I'm flying to Vegas in two weeks time. After that flights leaving Vegas and Phoenix are late at night .. I've been hearing that it gets so hot that the air isn't dense enough for planes to take off. Weird. Guess you won't have that problem.
[Corion]: Yay, vacation time now - one week off work (but a Perl workshop in the middle ;)) )
[talexb]: TStanley I just realized that I was in your area for a convention back in April. We were at the high school for the weekend, the one with the long driveway. Nice spot.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2017-06-23 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (548 votes). Check out past polls.