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.
|
|
|
|
|
![]() |
||
Help required with javascript code
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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 |
|
|
|
|||
|
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. |
![]() |
| Tags |
| numeric functions |
| Thread Tools | |
|
|
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 |