Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Message from discussion Need some JavaScript puzzles
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jorge  
View profile  
 More options Sep 30 2008, 3:39 pm
Newsgroups: comp.lang.javascript
From: Jorge <jo...@jorgechamorro.com>
Date: Tue, 30 Sep 2008 12:39:30 -0700 (PDT)
Local: Tues, Sep 30 2008 3:39 pm
Subject: Re: Need some JavaScript puzzles
On Sep 29, 11:49 pm, Dr J R Stockton <J.R.Stock...@physics.org> wrote:

> On Sep 29, 9:02 pm, Jorge <jo...@jorgechamorro.com> wrote:

> > While writing 'my version', I was going to 'logically' test the bits
> > with an '&', but I have discovered that the & operator operates on
> > just 32 bits, not on the 53 available in the mantissa of a 'number'
> > primitive value:

> Agreed, but one can access all bits of a Double for logical operations
> by using arithmetic.  Working example :
> <URL:http://www.merlyn.demon.co.uk/js-misc0.htm#TC>

Yes, that's what I did, see:

function toBinaryString (number) {
  var weight= Math.pow(2, 52), binStr= '', decimalPoint;
  do {
    if (number >= weight) {
      number-= weight;
      binStr+= '1';
    } else { binStr+= binStr ? '0' : ''; }

    if (((weight/= 2) < 1) && !decimalPoint) {
        decimalPoint= 1;
        if (number) {
          binStr+= binStr ? '.' : '0.';
        } else { binStr+= binStr ? '' : '0'; }
    }
  } while (!decimalPoint || (number && weight))
  return binStr;

};

--
Jorge.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.