Help required with javascript code

This is a discussion on "Help required with javascript code" within the JavaScript Forum section. This forum, and the thread "Help required with javascript code are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 20th, 2006, 10:56
New Member
Join Date: Oct 2006
Location: Lancasire
Age: 33
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Help required with javascript code

Hi, I am hoping someone would give me a few minutes with the following. I have the task of translating some javascipt into Visual Basic. Unfortunately my knowledge of Javascript is pretty poor and I am having difficulty in working out what the javascript code is doing. The code is as follows :

================================================

acc=0
i=1
for (i = 1; i <= 8; i++) {
if (i > 1) {
cy = (acc & 7) * 8192
cy = cy % 65536
acc = pInt(acc/8) | cy
}
if (pdte.substring(i-1,i)=="/") {
acc = acc + 47
}
else {
acc = acc + 48 + (pdte.substring(i-1,i)*1)
}
acc = acc % 65536
}
return acc % pmod
}
function pInt(piwork)
{
var y
y = piwork + " "
if (y.indexOf(".") != -1)
{
return y.substr(0,y.indexOf(".")) * 1
}
return piwork
}
=============================================

For info pdte would be a date - i.e. 01/01/06

The parts I am having dificulty understanding are :

cy = (acc & 7) * 8192 (What does acc & 7) do ??

acc = pInt(acc/8) | cy (What does the pInt function return - is it for example : if 1234.9999 is passed to it does it return 1234??? Also what does the | cy do??

Are the substrings only passing one back one character each time??


I just need to know what these do so that I can use the VB equivalent.

Many Thanks
Tony
Reply With Quote

  #2 (permalink)  
Old Oct 20th, 2006, 21:16
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Help required with javascript code

(acc & 7) is a bitwise AND.

The % symbol is for modulus, i.e., a % b returns the integer remainder of a div b.

the substring function returns a substring whose length is determined by it two parameters. As in this case you are using i-1 and i, you are effectively retrieving a single character starting from position i-1. Remember string positions start from 0.

This next bit is a combination of normal sums and bitwise again. (acc / 8) | cy is the result of acc divided by 8 and then OR'ed with cy.

As far as I can see, the purpose of pInt is to return the integer part of a decimal number.
Reply With Quote
Reply

Tags
numeric functions

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
A new simple way to make a image slider- Javascript Code o0DarkEvil0o JavaScript Forum 1 May 20th, 2008 01:37
how can i use my javascript code with my asp.net page skat ASP.NET Forum 8 Mar 17th, 2008 02:57
For all Javascript Coding Experts, can you break down this code? BlackReef JavaScript Forum 12 Dec 10th, 2007 01:04
BB Code - JavaScript Input thing... How? JasonStanley JavaScript Forum 5 May 5th, 2007 10:46
Javascript code ignored by Netscape/Firefox commodorejim JavaScript Forum 2 Oct 14th, 2006 10:13


All times are GMT. The time now is 05:06.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43