Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7916477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:49:27+00:00 2026-06-03T14:49:27+00:00

I have a string contains 64 binary symbols. I need to convert it into

  • 0

I have a string contains 64 binary symbols.

I need to convert it into the decimal number. How can I do it in perl?

sub bin2dec {
    return unpack("N", pack("B64", substr("0" x 64 . shift, -64)));
}

doesn’t work. it converts just first 32 bit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:49:29+00:00Added an answer on June 3, 2026 at 2:49 pm

    From the docs,

    N  An unsigned long (32-bit) in "network" (big-endian) order.
    

    The 64 bit equivalent would be “Q>“.

    q  A signed quad (64-bit) value.
    Q  An unsigned quad value.
      (Quads are available only if your system supports 64-bit
      integer values _and_ if Perl has been compiled to support
      those. Raises an exception otherwise.)
    
    >   sSiIlLqQ   Force big-endian byte-order on the type.
        jJfFdDpP   (The "big end" touches the construct.)
    

    So you could use the following:

    unpack("Q>", pack("B64", substr("0" x 64 . shift, -64)))
    

    That said, the above is needlessly complicated. Whoever coded that was was probably not aware of oct‘s ability to parse binary numbers because the above can be reduced to

    oct("0b" . shift)
    

    But what do you do if you don’t have a 64-bit build of Perl? You need to use some kind of object that overloads math operations. You could use Math::BigInt, but I suspect that won’t be nearly as fast as Math::Int64.

    use Math::Int64 qw( string_to_int64 );
    string_to_int64(shift, 2)
    

    For example,

    $ perl -MMath::Int64=string_to_int64 -E'say string_to_int64(shift, 2);' \
       100000000000000000000000000000000
    4294967296
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string which contains binary data ( non-text data ). How do
I have a string which contains binary digits. How to separate string after each
I have a string that contains a known number of double values. What's the
I have a binary file. This file contains an UTF-8 string. Moreover, it is
I have a binary array. In the process of conversion it into string,due to
I have a string that contains a czech character. the string is 0bálka This
I have a string which contains only numbers. Now I want to remove all
I have a string which contains a series of bits (like 01100011) and some
If I have a string that contains a url (for examples sake, we'll call
Suppose I have a string that contains Ü. How would I find all those

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.