469,289 Members | 2,225 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

Need help understanding this part of code. Explanation in post(2008-04-18)

Hello.
I am not new to javascript but i saw a function or a part of code i am
not familiar with.
I am currently building a PHP wrapper to be able to encode fAES string
from php and decode them with javascript.

My main problem at this time is this little part of code.

var nonce = (new Date()).getTime();
for (var i=0; i<4; i++) {
counterBlock[i] = (nonce >>i*8) & 0xff;
}

I have absolutely no idea what the >>means as i have been unable to
find anything on this.
This code is JavaScript.

I know i am new to this group but, if i am at the wrong place to ask
for help, just move or delete my post.

P.S. i know i am asking a lot but, if someone has an idea how i can
reproduce this under PHP, i would greatly appreciate.

Thanks
Jun 27 '08 #1
1 838
<pa*****@patrick-isp.comwrote:
<snip>
My main problem at this time is this little part of code.

var nonce = (new Date()).getTime();
for (var i=0; i<4; i++) {
counterBlock[i] = (nonce >>i*8) & 0xff;
}

I have absolutely no idea what the >>means as i have been
unable to find anything on this.
The - >>- is the bitwise unsigned right shift operator (ECMA 262, 3rd
Ed. Section 11.7.3). The left hand side operand is converted into an
unsigned 32 bit integer and shifted right by the number of bits
specified by the right hand side operand (the result of the expression -
i*8 - in this case). The result is then converted back to a normal
javascript number (an IEEE double precision floating point number) and
that number is the evaluated result of the unsigned right shift
expression.

Incidentally, the - & - is the bidwise AND operator, so the effect is to
mask out all but the lower (right-most) byte of the shifted number.
This code is JavaScript.
It is.
I know i am new to this group but, if i am at the wrong place
to ask for help, just move or delete my post.
It seems like a reasonable question to ask here.
P.S. i know i am asking a lot but, if someone has an
idea how i can reproduce this under PHP, i would
greatly appreciate.
I have no idea at all. The PHP documentation is where I would start
looking (either PHP has an equivalent operator or it does not, but if
not the same effect could be achieved with other math operators), but
not right now.

Richard.
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Randy Harris | last post: by
14 posts views Thread by mistral | last post: by
3 posts views Thread by =?gb2312?B?zfW2rA==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.