Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: converting binary to decimal

by hippo (Archbishop)
on Jun 05, 2025 at 18:48 UTC ( [id://11165278]=note: print w/replies, xml ) Need Help??


in reply to converting binary to decimal

Why are you not using bigint?


🦛

Replies are listed 'Best First'.
Re^2: converting binary to decimal
by LanX (Saint) on Jun 06, 2025 at 14:02 UTC
    > using bigint

    FWIW

    use v5.12; use warnings; use bigint; #say my $bin = join "", map { int rand(2) ? '0': '1' } 1..100; say $bin = 1 . 0 x 8192 ; say oct("0b".$bin);

    1090748135619415929462984244733782862448264161996232692431832786189721 +331849119295216264234525201987223957291796157025273109870820177184063 +610979765077554799078906298842192989538609825228048205159696851613591 +638196771886542609324560121290553901886301017900252535799917200010079 +600026535836800905297805880952350501630195475653911005312364560014847 +426035293551245843928918752768696279344088055617515694349945406677825 +140814900616105920256438504578013326493565836047242407382442812245131 +517757519164899226365743722432277368075027627883045206501792761700945 +699168497257879683851737049996900961120515655050115561271491492515342 +105748966629547032786321505730828430221664970324396138635251626409516 +168005427623435996308921691446181187406395310665404885739434832877428 +167407495370993511868756359970390117021823616749458620969857006263612 +082706715408157066575137281027022310927564910276759160520878304632411 +049364568754920967322982459184763427383790272448438018526977764941072 +715611580434690827459339991961414242741410599117426060556483763756314 +527611362658628383368621157993638020878537675545336789915694234433955 +666315070087213535470255670312004130725495834508357439653828936077080 +978550578912967907352780054935621561090795845172954115972927479877527 +738560008204118558930004777748727761853813510493840581861598652211605 +960308356405941821189714037868726219481498727603653616298856174822413 +033485438785324024751419417183012281078209729303537372804574372095228 +703622776363945290869806258422355148507571039619387449629866808188769 +662815778153079393179093143648340761738581819563002994422790754955061 +288818308430079648693232179158765918035565216157115402992120276155607 +873107937477466841528362987708699450152031231862594203085693838944657 +061346236704234026821102958954951197087076546186622796294536451620756 +509351018906023773821539532776208676978589731966330308893304665169436 +185078350641568336944530051437491311298834367265238595404904273455928 +723949525227184617404367854754610474377019768025576605881038077270707 +717942221977090385438585844095492116099852538903974655703943973086090 +930596963360767529964938414598185705963754561497355827813623833288906 +309004288017321424808663962671333528009232758350873059614118723781422 +101460198615747386855096896089189180441339558524822867541113212638793 +675567650340362970031930023397828465318547238244232028015189689660418 +822976000815437610652254270163595650875433851147123214227266605403581 +781469090806576468950587661997186505665475715792896

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

Re^2: converting binary to decimal
by LanX (Saint) on Jun 05, 2025 at 20:09 UTC
      TinyPerl does have a BigInt module, but I wanted to come up with my own different approach.
Re^2: converting binary to decimal
by harangzsolt33 (Deacon) on Jun 06, 2025 at 01:29 UTC
    Well, that's like asking "Why don't you just buy an airplane ticket?" from someone who built a model airplane.

      Except that you have posted this in the Cool Uses For Perl section which explains right at the top:

      This section is the place to post useful code

      Nowhere in your OP have you stated that this code isn't intended for productive use. Perhaps you meant to post it somewhere else?


      🦛

        It is intended for my use. Lol But if you think it's good enough, then you can use it too. However, I have seen two other solutions here that are better. So, like I said before, even if you don't have something smart to say, if you post something bad, others will correct you. And it's a good way to learn. I've talked with ChatGPT trying to get it to give me an alternative unique sub that converts binary to decimal, but it kept referring me to the bigint module. But by posting this here, I already got some great ideas, which are even better than my solution was.
          A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11165278]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2026-01-20 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (125 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.