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 817391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:59:08+00:00 2026-05-15T01:59:08+00:00

I have a huge binary string, like: 1110 0010 1000 1111 0000 1100 1010

  • 0

I have a huge “binary” string, like: 1110 0010 1000 1111 0000 1100 1010 0111….

It’s length is 0 modulo 4, and may reach 500,000.

I have also a corresponding array: {14, 2, 8, 15, 0, 12, 10, 7, …}

(every number in the array corresponds to 4 bits in the string)

Given this string, this array, and a number N, I need to calculate the following substring string.substr(4*N, 4), i.e.:

for N=0 the result should be 1110

for N=1 the result should be 0010

I need to perform this task many many times, and my question is what would be the fastest method to calculate this substring ?

One method is to calculate the substring straight forward: string.substr(4*N, 4). I’m afraid this one is not efficient for such huge strings.

Another method is to use array[N].toString(2) and then wrap the result with zeros if needed. I’m not sure how fast is this.

May be you have any other ideas ?

  • 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-05-15T01:59:09+00:00Added an answer on May 15, 2026 at 1:59 am

    Where does the string come from? Why not represent the string not as binary, but as hex, and then you can store each four-binary-digit section as a single character? (You could obviously pack it twice that densely if you wanted, or actually now that I think of it, 4 times, since Javascript strings are 16-bit Unicode). Then finding a single group would be a single call to “charAt()”, and you’d just have to expand to the binary form via a lookup table.

    edit — oh well duhh, you already have an array. In that case don’t do the substring work at all; it’s crazy. Just grab the array element and translate it through a lookup array into the 4-binary-digit string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.