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

  • Home
  • SEARCH
  • 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 8835055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:10:19+00:00 2026-06-14T09:10:19+00:00

Is there a way to compress a JavaScript array of 250+ 1s and 0s

  • 0

Is there a way to compress a JavaScript array of 250+ 1s and 0s into something a little more manageable (say a shorter string) and then manageably decompress the same? Sort of like the way Google did its image encodings…

Thanks!

  • 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-14T09:10:21+00:00Added an answer on June 14, 2026 at 9:10 am

    I can give you almost 1:5 compression by encoding as base 32. I chose to include a simple length value to make it allow variable-length. Please see this fiddle demonstrating the technique with two functions that allow you to round-trip the value. (Or you can see an earlier, more naive hexadecimal version I created before @slebetman reminded me of the native number base conversion that exists in javascript.)

    Here’s sample output for one set of 250 1s and 0s. The number of characters does not count the leading “250|”:

    base 32, 50 chars: 250|qgl6alf1q2lbl1aclau3k5ana2kpals78alek59ilboeglajgu
    base 16, 63 chars: 250|D42A6555E1D0AABA854CAABC3A155750A995578742AAEA1532AAF0E85553878
    

    You can use a base 64 encoding to get it down to 42 characters, but be aware that with both the base 32 and base 64 versions you can end up with words in your final result that may be objectionable (please see the fiddle above for an example). The hex version can also have objectionable content, but much less so (a bad face bade a dad be a cad?)

    Please let me know if you need to save 8 more characters and I will work up additional script for you. Avoiding vowels could be one way to deal with the objectionable word problem. Let me know if you need to do this as well.

    If your bit strings will always be 250 characters, then the functions can be simplified a bit, but I didn’t want to make this assumption.

    For reference here’s the bits-to-base-32 function.

    function bitstringEncode(bitstring) {
        var i, l = bitstring.length,
            retval = l.toString() + '|';
        for (i = 0; i < l; i += 5) {
            retval += parseInt((bitstring.substr(i, 5) + '0000').substr(0, 5), 2).toString(32);
        }
        return retval;
    }
    

    This function will pad to the nearest 5 bits, and may generate a spurious extra character at the end for the length you are providing. I included a second version of each conversion function that pads to the nearest 10 bits, which may generate up to two spurious extra characters. I included them because if speed is important, they may (or may not) be faster, as they take larger chunks from the inputs.

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

Sidebar

Related Questions

is there any way to compress more jquery base file? what i have is
Is there is way to compress JavaScript code? e.g. function test(){ // some code
I was wondering if there was a way to compress javascript in realtime, much
Is there a way I can compress a long string (e.g. a long JSON
Maybe there are any way to compress small strings(86 chars) to something smaller? @a@1\s\215\c\6\-0.55955,-0.766462,0.315342\s\1\x\-3421.-4006,3519.-4994,3847.1744,sbs
Is there way to automatically maximize the output window on hitting build and then
Is there way to copy a file into Plone with WebDAV and have Plone
Is there a way for me to lossless compress text with the following characters(88
Is there a way to compress/uncompress JSON sent from an app server to a
So there are some folders that I would like to compress into tar.gz file

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.