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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:59:41+00:00 2026-05-22T12:59:41+00:00

First thing: must be done entirely in javascript. (JQuery/mootools optional) I have a series

  • 0

First thing: must be done entirely in javascript. (JQuery/mootools optional)

I have a series of 100 numbers each set 0,1,2, or 3 – these represents settings on the page. I would like to encode these to the shortest string possible to create a permalink to the page.

I am thinking the best way would be to store them in binary couplets, convert those couplets to a string, ant then urlencode the string.

However the best I have found so far is parseint( binary_var, 2 ), which coverts a binary number to a base_10 number. However to get the string short enough I’ll need a better system.

If I could convert to 64-bit encoding I could store all the data in just 4 chars, I think. I know urls support unicode now, and I believe I can use escape and unescape to encode/decode 64-bit chars, so the main thing I am looking for is a way to encode/decode binary data to 64-bit characters.

Of course I am not 100% sure this is the best way, or will even work, so it I am completely off track feel free to point me in the right direction.

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-05-22T12:59:41+00:00Added an answer on May 22, 2026 at 12:59 pm

    You can encode such arrays of numbers into a string, 3 per character, like this:

    function encodeBase4(base4) {
      var i, rv = [], n = ~~((base4.length + 2) / 3) * 3;
    
      for (i = 0; i < n; i += 3) {
        rv.push(
          32 +
          ((base4[i] || 0) & 3) +
          ((base4[i + 1] || 0) & 3) * 4 +
          ((base4[i + 2] || 0) & 3) * 16
        );
      }
    
      return String.fromCharCode.apply(null, rv);
    }
    

    You can then convert the other direction like this:

    function decodeBase4(str) {
      var i, rv = [], n = str.length;
    
      for (i = 0; i < n; ++i) {
        var b = str.charCodeAt(i) - 32;
        rv.push(b & 3);
        rv.push(~~(b / 4) & 3);
        rv.push(~~(b / 16) & 3);
      }
    
      return rv;
    }
    

    Here’s the jsfiddle which seems to work on its simple test case. (Note that you end up with a list that’s a multiple of 3 in length; you’d have to know how many real values there are and just ignore the zeros at the end.)

    Now these result strings will be “dirty” and require URL encoding if you’re putting them in URLs. If you packed only 2 numbers per character, you could make the resulting strings be all alphabetic, and thus you’d avoid the encoding penalty; however they’d be longer, of course.

    • 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.