32-bit Number * 32-bit Number = 64-bit result -> What about 32-bit operators?

32-bit Number * 32-bit Number = 64-bit result -> What about 32-bit operators?

Post by Dr J R Sto » Wed, 06 May 2009 01:13:24


In comp.lang.javascript message < XXXX@XXXXX.COM >, Sun, 3 May
2009 22:57:31, Lasse Reichstein Nielsen < XXXX@XXXXX.COM > posted:

Good.

The FAQ apparently contains no mention of 32-bit within JavaScript, and
no instance of the operators | ~ ^ >> >>> << . There're not often asked
about, but they fairly often appear in solutions here.

Using >>>0 seems to be the way to get an unsigned result from a signed
one by apparently adding 2^32 if necessary. That might be wanted by the
OP. The reverse is done by |0 .

I have a page partly about those operators, "JavaScript Uses of
Operators",
<URL: http://www.yqcomputer.com/ ; (I must update it to
answer the question I just asked myself) ... (I did).

<FAQENTRY> Something about 32-bit.
<FAQENTRY> Which parts of JavaScript get no mention in the FAQ?

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL: http://www.yqcomputer.com/ ; - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
 
 
 

32-bit Number * 32-bit Number = 64-bit result -> What about 32-bit operators?

Post by Lasse Reic » Wed, 06 May 2009 06:21:47

Dr J R Stockton < XXXX@XXXXX.COM > writes:


Indeed they do (I never noticed that >>> could be used that way).
The technical explanation is that the algorithms for >>> and | perform
ToUInt32 and ToInt32 on their first operand, and the operation then
returns that as the result.

Genrally, the internal conversions of operators can be very useful
(like prefix "+" which does ToNumber and '+""' which does ToString).

/L
--
Lasse Reichstein Holst Nielsen
'Javascript frameworks is a disruptive technology'