I need a way (preferably fast) to turn very larger numbers into an array of bits. I tried sprintf and then splitting, but it looks like sprintf can't do a binary print of numbers that large (up to 1<<80) - nor am I confident that was a really "speedy" way to approach the issue. It seems like there should be some easy way to do this.

Essentially if I start with the number 57, I want to end up with the array ( 1, 0, 0, 1, 1, 1 ) (low bit is the first element).

Alternatively, if I just had a good way of checking the xth bit of a number without building a bitmask (unless someone can clue me in on how to do that quickly) that would work.

Speed matters to me because I've got a lot of computations to run here and if I burn too many cycles the program will end up taking an impractical amount of time (months) to run.


In reply to Turning very larger numbers into an array of bits by gblack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.