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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:32:00+00:00 2026-05-27T07:32:00+00:00

I have JavaScript code that retrieves numerical vectors from a web-service. The original data

  • 0

I have JavaScript code that retrieves numerical vectors from a web-service. The original data is an array of doubles that is converted to a byte array and then base64 encoded. I decode from base64 in JavaScript, but then I don’t know how to transform the resulting bytes into an array of numbers.

  • 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-27T07:32:00+00:00Added an answer on May 27, 2026 at 7:32 am

    This was the only way I could think of off the top of my head to do it.

    function bytesToDouble(str,start) {
        start *= 8;
        var data = [str.charCodeAt(start+7),
                    str.charCodeAt(start+6),
                    str.charCodeAt(start+5),
                    str.charCodeAt(start+4),
                    str.charCodeAt(start+3),
                    str.charCodeAt(start+2),
                    str.charCodeAt(start+1),
                    str.charCodeAt(start+0)];
    
        var sign = (data[0] & 1<<7)>>7;
    
        var exponent = (((data[0] & 127) << 4) | (data[1]&(15<<4))>>4);
    
        if(exponent == 0) return 0;
        if(exponent == 0x7ff) return (sign) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
    
        var mul = Math.pow(2,exponent - 1023 - 52);
        var mantissa = data[7]+
            data[6]*Math.pow(2,8*1)+
            data[5]*Math.pow(2,8*2)+
            data[4]*Math.pow(2,8*3)+
            data[3]*Math.pow(2,8*4)+
            data[2]*Math.pow(2,8*5)+
            (data[1]&15)*Math.pow(2,8*6)+
            Math.pow(2,52);
    
        return Math.pow(-1,sign)*mantissa*mul;
    }
    
    var data = atob("AAAAAABsskAAAAAAAPmxQAAAAAAAKrF");
    
    alert(bytesToDouble(data,0)); // 4716.0
    alert(bytesToDouble(data,1)); // 4601.0
    

    This should give you a push in the right direction, though it took me a while to remember how to deal with doubles.

    One big caveats to note though:

    This relies on the atob to do the base64 decoding, which is not supported everywhere, and aside from that probably isn’t a great idea anyway. What you really want to do is unroll the base64 encoded string to an array of numbers (bytes would be the easiest to work with although not the most efficient thing on the planet). The reason is that when atob does its magic, it returns a string, which is far from ideal. Depending on the encoding the code points it maps to (especially for code points between 128 and 255) the resulting .charCodeAt() may not return what you expect.

    And there may be some accuracy issues, because after all I am using a double to calculate a double, but I think it might be okay.

    Base64 is fairly trivial to work with, so you should be able to figure that part out.

    If you did switch to an array (rather than the str string now), then you would obviously drop the .charCodeAt() reference and just get the indices you want directly.

    There is a functioning fiddle here

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

Sidebar

Related Questions

I have create a simple grid that retrieves data from a server through php.
I have a code that will allow FlowPlayer to retrieve a Javascript array and
I have some Javascript code that will programmatically register an COM interop assembly by
I have some JavaScript code that works in IE containing the following: myElement.innerText =
I have some javascript code that creates an img tag with a mouseover callback,
I have some Javascript code that creates 2 arrays: One for Product Category and
I have some jQuery/JavaScript code that I want to run only when there is
I have this javascript code below that uses jquery, it is suppoed to be
I have a bit of Javascript code that creates a save friendly version of
i have some javascript roll over code that works fine in firefox but when

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.